我的代码会将 .txt
文件中的数据读取到双向链表中。请你们看一下并告诉我这里出了什么问题。
TelephoneBookList * commandLoad(char* fileName) {
TelephoneBookList *(*createList)(TelephoneBookNode*, char[]) = createTelephoneBookList;
char entry[100];
TelephoneBookList* aList = NULL;
TelephoneBookNode* aNode = NULL;
FILE* telephoneListFile = NULL;
telephoneListFile = fopen(fileName, "r");
if (!telephoneListFile)
return NULL;
else {
while (!feof(telephoneListFile)) {
fgets(entry, 100, telephoneListFile);
if (strstr(entry, "#")) //skip the first 2 lines in text file
continue;
aList = (*createList)(aNode, entry); //call the below function
countEntry++;
}
aList->size = countEntry;
fclose(telephoneListFile);
return aList;
}
}
最佳答案
更改:
while (!feof(telephoneListFile)) {
fgets(entry, 100, telephoneListFile);
致:
while (fgets(entry, 100, telephoneListFile)) {
关于c - 无法返回双向链表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37141113/