搜外网>搜外问答>问答页面

C语言中,如何让关闭的后再打开的程序再次读取出文件内的内容?相关代码如下,请问是哪里出了问题呢?

不懂的不要乱答    谢谢!

void SaveStudent()
{
FILE *fp;
node *p=head;
fp=fopen(fname,"wb");
while (p!=NULL)
{
fwrite(&p->stu,sizeof(node),1,fp);
p=p->next;
}
fclose(fp);
printf ("ok\n");
system("pause"); //暂停
system("cls"); //清屏
}
void ReadStudent()
{
FILE *fp;
node *p=head;
int i=0,n=CountStudent();
if ((fp=fopen(fname,"rb"))==NULL)
{
printf ("文件尚未创建\n");
return;
}
for (i=0;i<n;i++)
{
fscanf(fp,"%ld %s %.1f %d %s %d %d %d %s %ld %s\n",&p->stu.num,p->stu.name,&p->stu.score,&p->stu.age,p->stu.sex,&p->stu.year,&p->stu.month,&p->stu.day,p->stu.adress,&p->stu.call,p->stu.e_mail);
p=p->next;
}
fclose(fp);
PrintStudent();
system("pause"); //暂停
system("cls"); //清屏
}

追加问题
    4 人参与回答
SEO培训招生中
188