不知道哪里错了,求指导
#include <stdio.h>#define N 5
struct student
{
char id[10];
char name[10];
int sub[4];
float ave;
int total;
}stu[N],a;
struct student grade;
main()
{
FILE *f1;
int i,j;
float ave[4];
printf("Please input the information of the 5 students and their grades \n");
for(i=0;i<N;i++){
stu[i].total = 0;
printf("NO.%d:",i+1);
scanf("%s %s",stu[i].id,stu[i].name);
for(j=0;j<4;j++){
scanf("%d", &stu[i].sub[j]);
stu[i].total += stu[i].sub[j];
}
stu[i].ave=(float)stu[i].total/4;
}
for(i=0;i<N;i++)
{
grade.sub[0]+=stu[i].sub[0];
grade.sub[1]+=stu[i].sub[1];
grade.sub[2]+=stu[i].sub[2];
grade.sub[3]+=stu[i].sub[3];
}
for(i=0;i<4;i++)
{
ave[i]=(float)grade.sub[i]/N;
}
for(i=1;i<N;i++)
{
for(j=0;j<N-i;j++)
{
if(stu[j].ave<stu[j+1].ave)
{
a=stu[j];
stu[j] = stu[j+1];
stu[j+1] = a;
}
}
}
printf(" 学生的平均分排名 \n");
printf("------------------------------\n");
for(i=0;i<N;i++)
printf("%-10s %-10s %.2f\n",stu[i].id,stu[i].name,stu[i].ave);
printf("******************************\n");
printf("******************************\n");
printf(" 每门课的平均分为 \n");
printf("———————————————\n");
printf("The average of SUB1: %.2f \n",ave[0]);
printf("The average of SUB2: %.2f \n",ave[1]);
printf("The average of SUB3: %.2f \n",ave[2]);
printf("The average of SUB4: %.2f \n",ave[3]);
printf("\n\n");
printf("OUTPUT:\n");
f1 = fopen("stud.data","w");
for(i=0;i<N;i++)
{
fprintf(f1,"%s %s %d %d %d %d %f",stu[i].id,stu[i].name,stu[i].sub[0],stu[i].sub[1],stu[i].sub[2],
stu[i].sub[3],stu[i].ave);
}
fclose(f1);
fprintf(stdout,"\n\n");
f1 = fopen("stud.data","r");
printf("ID NAME SUB1 SUB2 SUB3 SUB4 AVEARGE\n");
for(i=0;i<N;i++)
{
fscanf(f1,"%s %s %d %d %d %d %f",stu[i].id,stu[i].name,&stu[i].sub[0],&stu[i].sub[1],&stu[i].sub[2],
&stu[i].sub[3],&stu[i].ave);
fprintf(stdout,"%s %s %5d %5d %5d %6d %5.2f\n",stu[i].id,stu[i].name,stu[i].sub[0],
stu[i].sub[1],stu[i].sub[2],stu[i].sub[3],stu[i].ave);
}
fclose(f1);
}