forked from pn8rjlxip/System
parent
250632cce1
commit
0070fac2fa
@ -0,0 +1,23 @@
|
||||
//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);
|
||||
}
|
Loading…
Reference in new issue