已知文件中存有10 个学生的数学、政治、和英语三门课的成绩,试统计每一学生的平均成绩,并存入该文件中。
解:#include
struct student{ int number;
char cname[10];
int shuxue;
int zhengzhi;
int yingyu;
double ave;};
main()
{
FILE *fp;
struct student s[10];
int size;
int i;
size=sizeof(struct student);
if((fp=fopen(“student”,”ab+”))==NULL)
{
printf(“cannot open the file!”);
exit(0);
}
for(i=0;i