主题:[讨论]一个关于读取文件内容的困惑
while(!feof(stu_information))
{
test=(struct student*)malloc(sizeof(struct student));
if(num==1)
head=operation=test;
else
operation->next=test;
operation=test;
fscanf(stu_information,"%d%s%s%d",&operation->numble,operation->name,operation->sex,&operation->age);
num++;
}
operation->next=NULL;
operation=head;
while(operation!=NULL)
{
printf("%d %s %s %d\n",operation->numble,operation->name,operation->sex,operation->age);
operation=operation->next;
}
fclose(stu_information);
}
想请教一下就是若在文件stu_information里有两组结构体数据为什么这个函数会循环三次,就是会多读取一次数据而导致多开辟了一个空间导致最后一组数据是乱码啊
{
test=(struct student*)malloc(sizeof(struct student));
if(num==1)
head=operation=test;
else
operation->next=test;
operation=test;
fscanf(stu_information,"%d%s%s%d",&operation->numble,operation->name,operation->sex,&operation->age);
num++;
}
operation->next=NULL;
operation=head;
while(operation!=NULL)
{
printf("%d %s %s %d\n",operation->numble,operation->name,operation->sex,operation->age);
operation=operation->next;
}
fclose(stu_information);
}
想请教一下就是若在文件stu_information里有两组结构体数据为什么这个函数会循环三次,就是会多读取一次数据而导致多开辟了一个空间导致最后一组数据是乱码啊