这是用了好久才写出来的程序,结果运行下才发现不正确,老大们求不改变程序的基础的修改一下,谢谢了`````
#include<stdio.h>struct student
{char name[10];
int num;
int age;
char addr[15];
float score[3];
float avre;
}struct stud[4];
int main()
{struct stud[i]
int i;
printf("请输入各学生信息:姓名、学号、年龄、地址、三门课成绩:\n");
for(i=0;i<4;i++)
{scanf("%s %d %d %s %f %f %f",stud[i].name,&stud[i].num,&stud[i].age,&stud[i].addr,&stud[i].score[0],&stud[i].score[1],&stud[i].score[2]);
stud[i].aver=(stud[i].score[0]+stud[i].score[1]+stud[i].score[2])/3.0;
}
save();
display();
}
void save()
{FILE*fp;
int i;
if((fp=fopen("stu-list","wb"))==NULL)
{printf("cannot open file\n");
return;
}
for(i=0;i<4;i++)
if(fwrite(&stud[i],sizeof(struct student),1,fp)!=1)
printf("file write error\n");
fclose(fp);
}
void display()
{FILE*fp;
int i;
if((fp=fopen("d:\\fengyi\\exe\\stu_dat","rb"))==NULL)
{printf("cannot open file\n");
return;
}
for(i=0;i<4;i++)
{fread(&stud[i],sizeof(struct student),1,fp);
printf("%-10s %4d %4d %-15s %5.1f %5.1f %5.1f %5.1f\n",stud[i].name,stud[i].num,stud[i].age,stud[i].addr,stud[i].score[0],
stud[i].score[1],stud[i].score[2],stud[i].aver);
}
fclose(fp);
}