输出 n 个学生的学号、姓名及 m 门课程的成绩到文件 student.txt 中 #10

Merged
pvfj5ugro merged 2 commits from XZL_输出n个学生的学号、姓名及m门课程的成绩到文件中 into master 2 years ago

@ -307,7 +307,25 @@ void PrintScore(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