From 7681a396b060ea4006310e2dc4557b04ec638003 Mon Sep 17 00:00:00 2001 From: theBao Date: Sun, 5 Nov 2023 10:10:38 +0800 Subject: [PATCH] input and output --- .DS_Store | Bin 6148 -> 6148 bytes input.c | 44 ++++++++++++++++++++++++++++++-------------- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/.DS_Store b/.DS_Store index b6510babd6caef41ee13bafc3e131413add28c09..f6a6b6139af3fae857f228bdf3c84a5394f86189 100644 GIT binary patch delta 213 zcmZoMXfc@JFUrZlz`)4BAi%&-!jQ_K$B^uqlb^ghFc=|g0ICFsPlM|VZHlJj+W0}~nXEQs;Uw#1I CStE7; diff --git a/input.c b/input.c index 91cb3e3..452cf6c 100644 --- a/input.c +++ b/input.c @@ -1,33 +1,49 @@ #include "mysyslib.h" +void Print(Student*student){ + printf("%s,%s,%s,%.1lf,%.1lf,%.1lf,%.1lf\n",&student->id,&student->class,&student->name,student->score1,student->score2,student->score3,student->score); +} + +void allPrint(ss*stu){ + for(int i = 0; i < stu->nums; ++i){ + Print(&stu->student[i]); + } +} + void input(ss*stu){ - char *tmp = (char*)malloc(sizeof(char)*3); + char tmp[3]; do{ + int pst = stu->nums; printf("Id "); - // get + scanf("%s",&stu->student[pst].id); printf("\n"); - + printf("class "); - // get + scanf("%s",&stu->student[pst].class); printf("\n"); - + printf("name "); - // get + scanf("%s",&stu->student[pst].name); printf("\n"); - + printf("score1 "); - // get + scanf("%lf",&stu->student[pst].score1); printf("\n"); - + printf("score2 "); - // get + scanf("%lf",&stu->student[pst].score2); printf("\n"); - + printf("score3 "); - // get + scanf("%lf",&stu->student[pst].score3); printf("\n"); - + + stu->student[pst].score = stu->student[pst].score1 + stu->student[pst].score2 + stu->student[pst].score3; + stu->nums++; + printf("continue?\n"); scanf("%s",tmp); - }while(strcmp(tmp,"yes")); + }while(!strcmp(&tmp,"yes")); + + return; }