diff --git a/.main2.c.swp b/.main2.c.swp new file mode 100644 index 0000000..1cf5fae Binary files /dev/null and b/.main2.c.swp differ diff --git a/delete.c b/delete.c new file mode 100644 index 0000000..60f643d --- /dev/null +++ b/delete.c @@ -0,0 +1,19 @@ +#include "mysyslib.h" + +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")); +} diff --git a/init.c b/init.c new file mode 100644 index 0000000..80e20eb --- /dev/null +++ b/init.c @@ -0,0 +1,18 @@ +#include "mysyslib.h" + + 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; + } diff --git a/input.c b/input.c new file mode 100644 index 0000000..91cb3e3 --- /dev/null +++ b/input.c @@ -0,0 +1,33 @@ +#include "mysyslib.h" + +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")); +} diff --git a/main.c b/main.c index 288d6f5..97c7215 100644 --- a/main.c +++ b/main.c @@ -2,11 +2,15 @@ int main(){ char 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'){ break; }else{ diff --git a/mysyslib.h b/mysyslib.h index 7a37c57..2ab5774 100644 --- a/mysyslib.h +++ b/mysyslib.h @@ -1,3 +1,27 @@ #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); char mainMenu(); +void getCom(ss*); +void Print(Student*); +void allPrint(ss*); +void input(ss*); +void cancel(ss*); +void Select(ss*); diff --git a/output.c b/output.c new file mode 100644 index 0000000..520970f --- /dev/null +++ b/output.c @@ -0,0 +1,11 @@ +#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]); + } +} diff --git a/main_副本2.c b/unusemain.c similarity index 99% rename from main_副本2.c rename to unusemain.c index fde4e28..63ab658 100644 --- a/main_副本2.c +++ b/unusemain.c @@ -43,7 +43,7 @@ ss* init(int Nums){ ss* stu = (ss*)malloc(sizeof(ss)); if(!stu) return NULL; - stu->nums = Nums; + stu->nums = 0; stu->student = (Student*)malloc(sizeof(Student)*Nums); if(!stu->student) return NULL;