From 4dfff61c023482ac31065408c6068993d0dbd7e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E4=B8=96=E6=B3=A2?= <2783626707@qq.com> Date: Mon, 6 Nov 2023 22:42:04 +0800 Subject: [PATCH] fix:some strcmp caused bug --- .main2.c.swp | Bin 12288 -> 0 bytes delete.c | 4 +- input.c | 20 +--- main.c | 13 +-- menuoutput.c | 31 ++++-- mysyslib.h | 2 +- output.c | 6 +- unusemain.c | 288 +++++++++++++++++++++++++-------------------------- 8 files changed, 179 insertions(+), 185 deletions(-) delete mode 100644 .main2.c.swp diff --git a/.main2.c.swp b/.main2.c.swp deleted file mode 100644 index 1cf5faeab10b85c33189ab7b86788998d57c0e21..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2UuYaf9LJ}v)<#=f6p=zC(+erL>18*&mlW%ze@H_iHmSuBUuw|J?p$ue-tKjG zuM$fv7Fq;F5Q2Ra{~%Zu#Xo4pminL%J}81Og7^m%1g#GhDhdU^GrN1Yxl2O{@gXqF zeeQ05JHOw|d}ro26LQo2kBpAfJ!(I}wT+OM{yfA!AnQ98c5fu1VHktDUK}VI{OJuZ z*SAc!;)jtczS(}&bi5@>Ka~lng;9On^voGHF&Apw!BDLwe56S#AQe~z1?o|`@BS^M zXy{_8cjtD{yYHG@g}^d|R6r^q6_5%@1*8H}0jYpgKq|0S6o_i;$SE{-ebV4_$>+M3 z&*WBqNCl(&Km(ni1N?m_Ay>d3;Ct`|_!zto-UF|K7r-gt zfJra{3_w8_xVD9mAHi4PGPndTf;YfvPyrS=3hn_{H=|DQC3qe@1h#>#pacAK2igU$ zfuF(aU>2z0uiFXv2+V^CFbocW{XhZR0RcaC5b_CF03MhC!{7ke4|3p{O@y2UXMhI| zfgaEW?gO1*6Zq~nLcRePzkRQO;-~xCTEPyk>2W9Xe zD1jc(39jEt$S>e?a2dP<-Ue@hbD#nq2O78+{C*1|pMtYs9F#yG=mwj?70j7$!H3{A z@CtYtJO`%0BsdI)zyn|p;Pb2ttd&dCPT=J`Hg&v^1yMc>d-2m11v7+DT=P#<9GB($ zm6EvSrudufpA;6WVg|i5s@CXUnin@p)pYSgnSAIx$^5dgDZNDm5Y zyIr;OGLDHeryrc}o+jE*Ro;%RUP!TU?p$p+`4 zolMz`gb31Xs2Ir6k>$s9FmYJvRKW0A%uQ$9ji&3LiZ}}KC z@5Fr6TkegP`(n#I`X<^O_k1EwV|)YP=?r-y*#(#zG8(X`9(Zw%5C-HVzZN;ZNB8cf zgG#b7Xj=Qj0fmM>-&`8$y}e9Pq3PbROesU5Y1(L%TGS3*!A>TIx$!(ra(1q;Gj4D) zq&x-3hC~Le^MihsXC$7FoBdDijgaY3)?8*n8c`#i^Xowpuet8il03gGf9+O}*PUo3 zo`b4ikI?6p_ztLkV6$K)u0=HzoB2w74b_Hk#8%>~t3vPCRZQRX^w6^4;u*__GM=^b zICCc#Y|U*OyQs)_%bsBL>=~%lJx+7W`Wwll;|*wa$MI`f-*l&4A_pD8ks-UQ6CNKc zVn?Z~hh0T9+ErOZBj8&jG3x*Np z=Nj5eVLEYaim&gMGbwz9CCxEtY+`Bb9jPIk=2P3^G@4q|?9mLC_CZ*(J%9Hx6jjxgH zy_ob_gJUnzsBXuzT(p=Dp`DI5qgM8jtj%_v={B3=a}&`tyeK^wFf(E{ot~png$nums; ++i){ - if(strcmp(stu->student[i].id,ID)){ + if(strcmp(stu->student[i].id,ID) == 0){ for(int j = i; j < stu->nums-1; ++j){ stu->student[j] = stu->student[j+1]; } @@ -15,5 +15,5 @@ void cancel(ss*stu){ allPrint(stu); printf("continue?\n"); scanf("%s",tmp); - }while(strcmp(tmp,"yes")); + }while(!strcmp(tmp,"yes")); } diff --git a/input.c b/input.c index 452cf6c..4b81332 100644 --- a/input.c +++ b/input.c @@ -1,29 +1,19 @@ #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[3]; + char tmp[5]; do{ int pst = stu->nums; printf("Id "); - scanf("%s",&stu->student[pst].id); + scanf(" %s",stu->student[pst].id); printf("\n"); printf("class "); - scanf("%s",&stu->student[pst].class); + scanf(" %s",stu->student[pst].class); printf("\n"); printf("name "); - scanf("%s",&stu->student[pst].name); + scanf(" %s",stu->student[pst].name); printf("\n"); printf("score1 "); @@ -43,7 +33,7 @@ void input(ss*stu){ printf("continue?\n"); scanf("%s",tmp); - }while(!strcmp(&tmp,"yes")); + }while(!strcmp(tmp,"yes")); return; } diff --git a/main.c b/main.c index 97c7215..020a8e7 100644 --- a/main.c +++ b/main.c @@ -1,20 +1,11 @@ #include "mysyslib.h" int main(){ - char ipt; + int ipt; ss* stu = init(6); while(1){ - ipt = mainMenu(); - if(ipt=='i'){ - input(stu); - }else if(ipt=='o'){ - cancel(stu); - }else if(ipt=='m'){ - - }else if(ipt=='q'){ + if(mainMenu(stu)){ break; - }else{ - continue; } } return 0; diff --git a/menuoutput.c b/menuoutput.c index af044d8..fa519a5 100644 --- a/menuoutput.c +++ b/menuoutput.c @@ -1,30 +1,39 @@ #include "mysyslib.h" -char mainMenu() { - char out[4][8] = {"Input","Output","Order","Quit"}; - for(int i=1;i<5;i++){ +int mainMenu(ss *stu) { + char out[6][8] = {"input","delete","select","order","output","quit"}; + for(int i=1;i<7;i++){ for(int j=0;j<30;j++){ printf(" "); } printf("%d.%s\n",i,out[i-1]); } - char ipt; - scanf("%c",&ipt); + int ipt; + scanf("%d",&ipt); switch(ipt){ - case 'i': + case 1: printf("You are trying to Input info\n"); + input(stu); //录入学生信息 break; - case 'o': - printf("You are trying to Output info\n"); + case 2: + printf("You are trying to Delete info\n"); + cancel(stu); //删除学生信息 + break; + case 3: + printf("You are trying to Selete info\n"); break; - case 'm': + case 4: printf("You are trying to Make things ordered\n"); break; - case 'q': + case 5: + printf("You are trying to Output info\n"); + allPrint(stu); //输出所有学生信息 + break; + case 6: printf("You are about to Quit\n"); break; default: printf("Wrong input\n"); } - return ipt; + return (ipt==6)?1:0; } diff --git a/mysyslib.h b/mysyslib.h index 2ab5774..b678af7 100644 --- a/mysyslib.h +++ b/mysyslib.h @@ -18,7 +18,7 @@ typedef struct{ }ss; ss* init(int); -char mainMenu(); +int mainMenu(ss *stu); void getCom(ss*); void Print(Student*); void allPrint(ss*); diff --git a/output.c b/output.c index 520970f..0711a3b 100644 --- a/output.c +++ b/output.c @@ -1,11 +1,15 @@ #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); + 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){ + if(stu->nums){ for(int i = 0; i < stu->nums; ++i){ Print(&stu->student[i]); } + }else{ + printf("No data exist\n"); + } } diff --git a/unusemain.c b/unusemain.c index 63ab658..e69805c 100644 --- a/unusemain.c +++ b/unusemain.c @@ -5,147 +5,147 @@ // Created by theBao on 2023/11/4. // -#include -#include -#include - -typedef struct{ - char *id; - char *class; - char *name; - double score1; - double score2; - double score3; - double score; -}Student; - -typedef struct{ - Student* student; - int nums; -}ss; - -ss* init(int); -void toMenu(ss*); -void getCom(ss*); -void Print(Student*); -void allPrint(ss*); -void input(ss*); -void cancel(ss*); -void Select(ss*); - -int main(int argc, const char * argv[]){ - ss* stu = init(6); - toMenu(stu); - return 0; -} - -ss* init(int Nums){ - ss* stu = (ss*)malloc(sizeof(ss)); - if(!stu) return NULL; - - stu->nums = 0; - stu->student = (Student*)malloc(sizeof(Student)*Nums); - if(!stu->student) return NULL; - - for(int i = 0; i < Nums; ++i){ - stu->student[i].id = (char*)malloc(sizeof(char)*5); - stu->student[i].class = (char*)malloc(sizeof(char)*2); - stu->student[i].name = (char*)malloc(sizeof(char)*10); - - } - return stu; -} - -void toMenu(ss*stu){ - printf(" 1.input\n"); - printf(" 2.delete\n"); - printf(" 3.select\n"); - printf(" 4.order\n"); - printf(" 5.output\n"); - printf(" 6.quit\n"); - printf("please input your option\n"); - getCom(stu); -} - -void getCom(ss* stu){ - int option; - scanf("%d",&option); - if(option == 1) input(stu); - else if(option == 2) cancel(stu); - else if(option == 3) Select(stu); - //else if(option == 4) sort(stu); - else if(option == 5) ; - else return; -} - -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); - do{ - printf("Id "); - // get - printf("\n"); - - printf("class "); - // get - printf("\n"); - - printf("name "); - // get - printf("\n"); - - printf("score1 "); - // get - printf("\n"); - - printf("score2 "); - // get - printf("\n"); - - printf("score3 "); - // get - printf("\n"); - - printf("continue?\n"); - scanf("%s",tmp); - }while(strcmp(tmp,"yes")); - - toMenu(stu); -} - -void cancel(ss*stu){ - char* tmp = (char*)malloc(sizeof(char)*3); - do{ - char*ID = (char*)malloc(sizeof(char)*5); - scanf("%s",ID); - for(int i = 0; i < stu->nums; ++i){ - if(strcmp(stu->student[i].id,ID)){ - for(int j = i; j < stu->nums-1; ++j){ - stu->student[j] = stu->student[j+1]; - } - } - } - allPrint(stu); - printf("continue?\n"); - scanf("%s",tmp); - }while(strcmp(tmp,"yes")); - toMenu(stu); -} - -void Select(ss*stu){ - char* tmp = (char*)malloc(sizeof(char)*3); - do{ - ; - }while(0); -} - -//void insert(ss*stu) +// #include +// #include +// #include +// +// typedef struct{ +// char *id; +// char *class; +// char *name; +// double score1; +// double score2; +// double score3; +// double score; +// }Student; +// +// typedef struct{ +// Student* student; +// int nums; +// }ss; +// +// ss* init(int); +// void toMenu(ss*); +// void getCom(ss*); +// void Print(Student*); +// void allPrint(ss*); +// void input(ss*); +// void cancel(ss*); +// void Select(ss*); +// +// int main(int argc, const char * argv[]){ +// ss* stu = init(6); +// toMenu(stu); +// return 0; +// } +// +// ss* init(int Nums){ +// ss* stu = (ss*)malloc(sizeof(ss)); +// if(!stu) return NULL; +// +// stu->nums = 0; +// stu->student = (Student*)malloc(sizeof(Student)*Nums); +// if(!stu->student) return NULL; +// +// for(int i = 0; i < Nums; ++i){ +// stu->student[i].id = (char*)malloc(sizeof(char)*5); +// stu->student[i].class = (char*)malloc(sizeof(char)*2); +// stu->student[i].name = (char*)malloc(sizeof(char)*10); +// +// } +// return stu; +// } +// +// void toMenu(ss*stu){ +// printf(" 1.input\n"); +// printf(" 2.delete\n"); +// printf(" 3.select\n"); +// printf(" 4.order\n"); +// printf(" 5.output\n"); +// printf(" 6.quit\n"); +// printf("please input your option\n"); +// getCom(stu); +// } +// +// void getCom(ss* stu){ +// int option; +// scanf("%d",&option); +// if(option == 1) input(stu); +// else if(option == 2) cancel(stu); +// else if(option == 3) Select(stu); +// //else if(option == 4) sort(stu); +// else if(option == 5) ; +// else return; +// } +// +// 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); +// do{ +// printf("Id "); +// // get +// printf("\n"); +// +// printf("class "); +// // get +// printf("\n"); +// +// printf("name "); +// // get +// printf("\n"); +// +// printf("score1 "); +// // get +// printf("\n"); +// +// printf("score2 "); +// // get +// printf("\n"); +// +// printf("score3 "); +// // get +// printf("\n"); +// +// printf("continue?\n"); +// scanf("%s",tmp); +// }while(strcmp(tmp,"yes")); +// +// toMenu(stu); +// } +// +// void cancel(ss*stu){ +// char* tmp = (char*)malloc(sizeof(char)*3); +// do{ +// char*ID = (char*)malloc(sizeof(char)*5); +// scanf("%s",ID); +// for(int i = 0; i < stu->nums; ++i){ +// if(strcmp(stu->student[i].id,ID)){ +// for(int j = i; j < stu->nums-1; ++j){ +// stu->student[j] = stu->student[j+1]; +// } +// } +// } +// allPrint(stu); +// printf("continue?\n"); +// scanf("%s",tmp); +// }while(strcmp(tmp,"yes")); +// toMenu(stu); +// } +// +// void Select(ss*stu){ +// char* tmp = (char*)malloc(sizeof(char)*3); +// do{ +// ; +// }while(0); +// } +// +// //void insert(ss*stu)