c/c++语言开发共享无法正确扫描LinkedList的文件

我需要帮助找出如何正确扫描文本文件以将信息放入链接列表。 该文件是:

12 JackSprat 2 1 65000 13 HumptyDumpty 5 3 30000 17 BoPeep 2 3 30000 20 BoyBlue 3 2 58000 0 

0指示文件何时结束。 每当我运行我的代码时,它会循环5次,但只保存第一行。 当我打印链表的信息时,它只打印第一行5次。 我需要读取整个文件然后停在0但我很难过。 这是我的代码。

 struct employeeData* initializeList(struct employeeData *head, FILE *ifp ){ struct employeeData *temptr; struct employeeData *newnode; printf("testinn"); while(!feof(ifp)) { newnode = (struct employeeData*)malloc(sizeof(struct employeeData)); if (head == NULL) { head = newnode; head->next = NULL; } else { temptr = head; while(temptr->next != NULL) { temptr = temptr->next; } temptr->next = newnode; } fscanf(ifp, "%d%s%d%d%lf", &newnode->EMP_ID, &newnode->name, &newnode->dept, &newnode->rank, &newnode->salary); } return head;} 

如果我删除printf(“testin n”),那真的很奇怪; 然后代码在cmd提示符下崩溃。

    newnode =(struct employeeData *)malloc(sizeof(struct employeeData)); add string:newnode-> next = NULL;

    或使用calloc

    如果head!= NULL然后返回不变的头,这正是你想要的?

      以上就是c/c++开发分享无法正确扫描LinkedList的文件相关内容,想了解更多C/C++开发(异常处理)及C/C++游戏开发关注计算机技术网(www.ctvol.com)!)。

      本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

      ctvol管理联系方式QQ:251552304

      本文章地址:https://www.ctvol.com/c-cdevelopment/522551.html

      (0)
      上一篇 2020年12月10日
      下一篇 2020年12月10日

      精彩推荐