请教各位高手个问题
#include<stdio.h>#define N 4
struct student
{
char name[10];
int num;
char addr[10];
float grade[3];
float average;
};
main()
{
FILE *fp;
int i, j, k, sum=0;
struct student stud[N];
char filename[10];
printf("Enter the filename:\n");
scanf("%s",filename);
printf("Enter the information:\n");
for(i=0;i<N;i++)
{
scanf("%s%d%s",stud[i].name,&stud[i].num,stud[i].addr);
for(j=0;j<3;j++)
scanf("%f",&stud[i].grade[j]);
}
for(i=0;i<N;i++)
{
for(j=0;j<3;j++)
sum=sum+stud[i].grade[j];
stud[i].average=sum/3;
}
if((fp=fopen(filename,"wb"))==NULL)
{
printf("cannot open file\n");
exit(0);
}
for(k=0;k<N;k++)
fwrite(&stud[i],sizeof(struct student),1,fp);
fclose(fp);
}
程序没发现错 运行时输入第一行然后Enter 出错
劳烦各位大侠了