LIST *list;
list = createList();
FILE *file = fopen("test.txt","r");
char line[50];
char* token;
while(fgets(line,sizeof(line),file))
{
token = strtok(line," ,:=");
while (token != NULL)
{
printf("\n%s",token);
token = strtok(NULL," ,:=");
}
}
这段代码正确地将我文件中的行分隔成标记。现在,我想将它们插入到链表中。但是在 while 循环中添加 addNode 函数:
while (tp != NULL)
{
printf ("\n%s",token);
token = strtok (NULL, " ,:=");
addNode(li,&token);
}
插入时不起作用。
addNode 函数是:(来自给定的库)
int addNode (LIST* pList, void* dataInPtr)
{
bool found;
bool success;
NODE* pPre;
NODE* pLoc;
found = _search (pList, &pPre, &pLoc, dataInPtr);
if (found)
return (+1);
success = _insert (pList, pPre, dataInPtr);
if (!success)
return (-1);
return (0);
}
有人对此有任何想法吗?