将从文件读取的字符串插入到链表中
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);
}
有人对此有想法吗?
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," ,:=");
}
}
this piece of code separates the lines in my file into tokens correctly.
now , I want to insert them into a linked list. But adding addNode function inside the while loop :
while (tp != NULL)
{
printf ("\n%s",token);
token = strtok (NULL, " ,:=");
addNode(li,&token);
}
does not work while inserting.
the addNode function is : (from the given library)
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);
}
Anyone has an idea about this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能是问题所在:
更改为:
This is possibly the problem:
change to: