From 531518b4d1de946fe2d18f167259838d3b2b36af Mon Sep 17 00:00:00 2001 From: xuzigui <3542624849@qq.com> Date: Sat, 15 Apr 2023 17:32:56 +0800 Subject: [PATCH] =?UTF-8?q?XZG=5F=E4=BB=8E=E6=96=87=E4=BB=B6=E4=B8=AD?= =?UTF-8?q?=E8=AF=BB=E5=8F=96=E5=AD=A6=E7=94=9F=E7=9A=84=E5=AD=A6=E5=8F=B7?= =?UTF-8?q?=E3=80=81=E5=A7=93=E5=90=8D=E5=8F=8A=E6=88=90=E7=BB=A9=E7=AD=89?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E5=86=99=E5=85=A5=E5=88=B0=E7=BB=93=E6=9E=84?= =?UTF-8?q?=E4=BD=93=20stu=20=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 226cfee..06c70dc 100644 --- a/README.md +++ b/README.md @@ -366,6 +366,24 @@ void WritetoFile(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); } ``` \ No newline at end of file