int main()
結構圖
{ int id
char name[11];
int a,b,c;
} t,ST[5];
int i,j;
FILE *fp1,* fp2
if((FP 1 = fopen(" d:\ \ stud . dat "," r"))==NULL)
{ printf("f1打開錯誤!\ n ");
返回1;
}
if((fp2 = fopen(" d:\ \ studsort . dat "," w"))==NULL)
{ printf("f2打開錯誤!\ n ");
return 2;
}
for(I = 0;我& lt5;i++)
fscanf(fp1," %d%s%d%d%d ",& amp聖[我]。id,st[i]。姓名& amp聖[我]。壹,& amp聖[我]。b & amp;聖[我]。c);
for(I = 0;我& lt4;i++)
for(j = 0;j & lt4-I;j++)
?if(st[j].a+st[j]。b+st[j]。c & ltst[j+1]。a+st[j+1]。b+st[j+1]。c)
?{ t = ST[j];
ST[j]= ST[j+1];
ST[j+1]= t;
?}
for(I = 0;我& lt5;i++)
{ printf("%d %10s %4d %4d %4d?%7.2f\n ",st[i]。id,st[i]。姓名,聖[我]。a,st[i]。b,
聖[我]。c,(st[i].a+st[i]。b+st[i]。c)/3.0);
fprintf(fp2," %d %10s %4d %4d %4d?%7.2f\n ",st[i]。id,st[i]。姓名,聖[我]。a,st[i]。b,
聖[我]。c,(st[i].a+st[i]。b+st[i]。c)/3.0);
}
fclose(FP 1);
fclose(fp2);
返回0;
}