|
|
@ -366,6 +366,24 @@ void WritetoFile(STU stu[],int n,int m)
|
|
|
|
```
|
|
|
|
```
|
|
|
|
void ReadfromFile(STU stu[],int *n,int *m)
|
|
|
|
void ReadfromFile(STU stu[],int *n,int *m)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
FILE *fp;
|
|
|
|
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
if ((fp = fopen("student.txt","r")) == NULL)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("Failure to open score.txt!\n");
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fscanf(fp, "%d\t%d", n, m); //从文件中读出学生人数,课程门数
|
|
|
|
|
|
|
|
for (i=0; i<*n; i++) //学生人数保存在n指向的储存单元
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
fscanf(fp, "%10ld", &stu[i].num);
|
|
|
|
|
|
|
|
fscanf(fp, "%10s", stu[i].name);
|
|
|
|
|
|
|
|
for (j=0; j<*m; j++) //课程门数保存在m指向的储存单元
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
fscanf(fp, "%10f", &stu[i].score[j]); //不能用%10.0f
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fscanf(fp, "%10f%10f", &stu[i].sum, &stu[i].aver); //不能用%10.0f
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
```
|