我对链表的 c 代码完全感到困惑。该代码在 Visual Studio 中正常工作,但在 Linux 中不能正常工作。代码如下
typedef struct map
{
char key[50];
char value[50];
struct map* next;
} map_t;
void AddEntry( map_t** head, char* key, char* value )
{
map_t* newEntry = (map_t*)malloc(sizeof(map_t) );
strcmp( newEntry->key, key);
strcmp( newEntry->value, value);
newEntry->next = NULL;
if ( *head == NULL )
{
*head = newEntry;
}
else
{
map_t** currentEntry = head;
while ( (*currentEntry)->next != NULL )
{
*currentEntry = (*currentEntry)->next;
}
(*currentEntry)->next = newEntry;
}
}
这是我的电话:
map_t* localListHead = NULL;
AddEntry( &localListHead, "??", "Test" );
有人看到我没有看到的东西吗?