weixin_49362364 2022-06-06 15:16 采纳率: 100%
浏览 69
已结题

这段程序不知道什么用,有人可以看看吗

int n;
if ((fp = fopen("student.txt", "a")) == NULL)
{
printf("File open error!\n");
exit(1);
}
fclose(fp);
if ((fp = fopen("student.txt", "r")) == NULL)
{
printf("File open error!\n");
exit(1);
}
p1 = (struct student*)malloc(sizeof(struct student));
p1->next = NULL;
head = p1;
while (!feof(fp))
{
if (fread(p1, sizeof(struct student), 1, fp) != 1)
break;
p2 = (struct student*)malloc(sizeof(struct student));
p2->next = NULL;
p1->next = p2;
p1 = p2;
}
}

  • 写回答

3条回答 默认 最新

  • nanke_yh 新星创作者: 数据科学与机器学习技术领域 2022-06-06 15:31
    关注

    首先判断student.txt是否可读可写,然后将txt文件中按照结构体student的内容分别读出并保存在指针p1内存上。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 6月14日
  • 已采纳回答 6月6日
  • 创建了问题 6月6日