From 0070fac2fa17d066ac8145a0e7cb1070db50d514 Mon Sep 17 00:00:00 2001 From: tong tong zhang Date: Fri, 21 Apr 2023 23:42:18 +0800 Subject: [PATCH] =?UTF-8?q?17=E4=BB=8E=E6=96=87=E4=BB=B6=E4=B8=AD=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=E5=AD=A6=E7=94=9F=E7=9A=84=E5=AD=A6=E5=8F=B7=E3=80=81?= =?UTF-8?q?=E5=A7=93=E5=90=8D=E5=8F=8A=E6=88=90=E7=BB=A9=E7=AD=89=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E5=86=99=E5=85=A5=E5=88=B0=E7=BB=93=E6=9E=84=E4=BD=93?= =?UTF-8?q?=E6=95=B0=E7=BB=84stu=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ztt17.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 ztt17.md diff --git a/ztt17.md b/ztt17.md new file mode 100644 index 0000000..e15031e --- /dev/null +++ b/ztt17.md @@ -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); +} \ No newline at end of file