请教关于fscanf函数的问题
程序代码:fprintf(save," Name Num Chinese Math English Allscore\n");
p1=head;
fprintf(save," %-14s%-8d%-12.2f%-10.2f%-12.2f%-0.2f\n",p1->Name,p1->Num,p1->Score.Chinese,p1->Score.Math,p1->Score.English,p1->Allscore);
while(p1->next!=NULL)
{
p1=p1->next;
fprintf(save," %-14s%-8d%-12.2f%-10.2f%-12.2f%-0.2f\n",p1->Name,p1->Num,p1->Score.Chinese,p1->Score.Math,p1->Score.English,p1->Allscore);
}
p1->next=NULL;
fclose(save);
printf("保存成功!\n");我是用如上方式将信息保存出去的
在硬盘中打开已保存的文件就是这样
这都没有问题 但是就不会怎么将该文件读取了
这是读取部分的代码
程序代码:int fs=0;
char filename[20];
FILE *load;
printf("请输入要读取的文件名:");
scanf("%s",&filename);
if((load=fopen("filename.txt","r+"))==NULL)
{
printf("No find!\n");
return head;
}
fseek(load,72,0);
struct student *p1;
p1=(struct student *)malloc(length);
fscanf(load," %-14s%-8d%-12.2f%-10.2f%-12.2f%-0.2f",&p1->Name,&p1->Num,&p1->Score.Chinese,&p1->Score.Math,&p1->Score.English,&p1->Allscore);
head=p1;
for(;;)
{
p1=p1->next;
p1=(struct student *)malloc(length);
fs=fscanf(load," %-14s%-8d%-12.2f%-10.2f%-12.2f%-0.2f",&p1->Name,&p1->Num,&p1->Score.Chinese,&p1->Score.Math,&p1->Score.English,&p1->Allscore);
if(fs==EOF)
{
p1=NULL;
break;
}
}
fclose(load);
printf("读取成功!\n");
system("pause");
getchar();
return head;








