这是一道关于文件保存的c语言的编程题——我是个初学者 求详解:不知道哪个错了无法输入
#include<stdio.h>#include<conio.h>
struct student
{ int sno;
char name[30] ;
char sex;
int score[3];
float sum;
float average;
} stu[1000];
int main()
{ void save(int n);
void read(int n);
int n;
int i;
scanf ("%d",&n);
for(i=0;i<n;i++)
{scanf("%d%s%s%d%d%d",&stu[i].sno,stu[i].name,stu[i].sex,&stu[i].score[0],
&stu[i].score[1],&stu[i].score[2]) ;
stu[i] .sum=(stu[i].score[0]+stu[i].score[1]+stu[i].score[2]);
stu[i] .average=stu[i].sum/3 ; }
printf("....................................\n");
save(n);
read(n);
printf("....................................\n") ;
getch();
return 0;
}
void save(int n)
{FILE *fp;
int i;
if((fp=fopen("stud.dat","wb"))==NULL)
{printf("cannot open file\n");
return;
}
for(i=0;i<n;i++)
if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)
printf("file write error\n");
fclose(fp) ;
}
void read(int n)
{int i;
FILE *fp;
if((fp=fopen("stud.dat","rb"))==NULL)
{printf("cannot open file\n");
}
for(i=0;i<n;i++)
{fread(&stu[i],sizeof(struct student),1,fp);
printf("%d%s%s%d%d%d",&stu[i].sno,&stu[i].name,&stu[i].sex,&stu[i].score[0],
&stu[i].score[1],&stu[i].score[2] );}
fclose(fp);
}