You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
737 B
23 lines
737 B
2 years ago
|
//17从文件中读取学生的学号、姓名及成绩等信息写入到结构体数组stu中
|
||
|
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);
|
||
|
}
|