Merge pull request '输出 n 个学生的学号、姓名及 m 门课程的成绩到文件 student.txt 中' (#10) from XZL_输出n个学生的学号、姓名及m门课程的成绩到文件中 into master

XZG_交换法实现字符串按字典顺序排序
pvfj5ugro 2 years ago
commit 3286ed8637

@ -340,7 +340,25 @@ void PrintScore(STU stu[],int n,int m)
``` ```
void WritetoFile(STU stu[],int n,int m) void WritetoFile(STU stu[],int n,int m)
{ {
FILE *fp;
int i, j;
if((fp = fopen("student.txt","w")) == NULL)
{
printf("Failure to open score.txt!\n");
exit(0);
}
fprintf(fp, "%d\t%d\n", n, m); //将学生人数和课程门数写入文件
for (i=0; i<n; i++)
{
fprintf(fp, "%10ld%10s", stu[i].num, stu[i].name);
for (j=0; j<m; j++)
{
fprintf(fp, "%10.0f", stu[i].score[j]);
}
fprintf(fp, "%10.0f%10.0f\n", stu[i].sum, stu[i].aver);
}
fclose(fp);
} }
``` ```

Loading…
Cancel
Save