c - 无法返回双向链表

标签 c linked-list doubly-linked-list

我的代码会将 .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/

相关文章:

c - 我想使用箭头键在 C 语言中的屏幕上移动符号

c - 在递归函数中删除链表的节点

在C中创建链接列表

java - 为什么这会从我的 LinkedList 中删除所有元素?

c - 特定情况下的段错误(核心转储)

c++ - 双向链表中的自定义数据类型

c - 验证电子邮件域的更好方法?

c - 读取线无法正常工作

c++ - 在hackerrank平台上的列表中插入节点时出现段错误

c++ - 1 << 31 产生错误, "The result of the ' <<' expression is undefined"