From a21ce528e41c25aebc7d4a8ace6d80644e93284e Mon Sep 17 00:00:00 2001 From: junj2ejj Date: Tue, 16 May 2017 13:42:48 +0900 Subject: [PATCH] 1.2.3 delete 1.2.2 --- add.c | 8 +- csv.c | 492 +++++++++++++++++++++++++------------------------- fdelete.c | 4 +- find.c | 12 +- functions.h | 17 +- main.c | 503 +++++++++++++++++++++++++-------------------------- sort.c | 510 ++++++++++++++++++++++++++++------------------------ 7 files changed, 793 insertions(+), 753 deletions(-) diff --git a/add.c b/add.c index 4398842..488b0a0 100644 --- a/add.c +++ b/add.c @@ -21,13 +21,13 @@ void add(struct task **top,struct task **end){ temp = temp->next; } //value for giving id - printf("名前を入力してください\n"); + printf("insert name:\n"); gets(temp->name); - printf("メールアドレスを入力してください\n"); + printf("insert mail:\n"); gets(temp->mail); - printf("グループを入力してください\n"); + printf("insert group:\n"); gets(temp->group); - printf("性別を入力してください(1は男性、2は女性で)\n"); + printf("insert sex (1)male (2)female\n"); scanf("%d",&sex); temp->next = NULL; temp->sex = sex; diff --git a/csv.c b/csv.c index 0734a83..c39d1c1 100644 --- a/csv.c +++ b/csv.c @@ -1,245 +1,247 @@ -#include -#include -#include -#include "functions.h" - -void csv_import(struct task **top, struct task **end){ - //load csv - FILE *fp; //ファイル宣言 - char filename[SIZE];//filename - printf("filename (csv format):"); - gets(filename);//input filename - struct task *temp = NULL; - int inputcode; - struct task *temp_front = NULL; - int id; - int count; - - int filename_count = 0; - char pot = '.'; - char c = 'c'; - char s = 's'; - char v = 'v'; - filename_count = strlen(filename); - filename[filename_count] = pot; - filename[filename_count+1] = c; - filename[filename_count+2] = s; - filename[filename_count+3] = v; - filename[filename_count+4] = '\0'; - printf("loading %s\n",filename); - - - if ((*top) == NULL){ - - count = 1; - printf("loading data from file...\n"); - temp = (struct task *)malloc(sizeof(struct task)); - temp->id = count; - (*top) = temp; - (*end) = temp; - - } else { - - printf("buffer data existed,(1)overwrite (2) write after existed data in file\n"); - inputcode = get_input(); - if (inputcode == 1){ - clear_list(&(*top),&(*end)); - (*top) = NULL; - (*end) = NULL; - (*top) = (struct task *)malloc(sizeof(struct task)); - temp = (*top); - (*end) = temp; - count = 1; - } else if (inputcode == 2){ - temp = (*top); - count = (*end)->id; - count++; - while(temp->next != NULL){ - temp = temp->next; - //count++; - } - } else { - printf("ERROR ,return to main menu.\n"); - return; - } - } - - if ((fp =fopen(filename,"r")) == NULL){ - fprintf(stderr,"ファイルが開けません\n"); - } else { - while(fscanf(fp,"%d,%[^,],%[^,],%[^,],%d\n",&id,temp->name,temp->mail,temp->group,&(temp->sex))!= EOF){ - temp-> id = count; - temp_front = temp; - temp->next = (struct task *)calloc(1,sizeof(struct task)); - temp = temp->next; - count++; - printf("."); - } - (*end) = temp_front; - printf("\n%d members load successfully.\n",count-1); - fclose(fp); - } -} - -void txt_import(struct task **top, struct task **end){ - //load txt - FILE *fp; //ファイル宣言 - char filename[SIZE];//filename - printf(" filename(txt format):"); - gets(filename);//input filename - struct task *temp = NULL; - int inputcode; - struct task *temp_front = NULL; - int count; - int id; - - int filename_count = 0; - char pot = '.'; - char t = 't'; - char x = 'x'; - filename_count = strlen(filename); - filename[filename_count] = pot; - filename[filename_count+1] = t; - filename[filename_count+2] = x; - filename[filename_count+3] = t; - filename[filename_count+4] = '\0'; - printf("loading %s\n",filename); - - if ((*top) == NULL){ - - count = 1; - printf("loading data from file...\n"); - temp = (struct task *)malloc(sizeof(struct task)); - temp->id = count; - (*top) = temp; - (*end) = temp; - - } else { - - printf("buffer data existed,(1)overwrite (2) write after existed data in file\n"); - inputcode = get_input(); - if (inputcode == 1){ - clear_list(&(*top),&(*end)); - (*top) = NULL; - (*end) = NULL; - (*top) = (struct task *)malloc(sizeof(struct task)); - temp = (*top); - (*end) = temp; - count = 1; - } else if (inputcode == 2){ - temp = (*top); - count = (*end)->id; - count++; - while(temp->next != NULL){ - temp = temp->next; - - } - } else { - printf("ERROR ,return to main menu.\n"); - return; - } - } - - if ((fp =fopen(filename,"r")) == NULL){ - fprintf(stderr,"ファイルが開けません\n"); - } else { - while(fscanf(fp,"%d %s %s %s %d \n",&id,temp->name,temp->mail,temp->group,&(temp->sex))!= EOF){ - temp-> id = count; - temp_front = temp; - temp->next = (struct task *)calloc(1,sizeof(struct task)); - temp = temp->next; - count++; - printf("."); - } - (*end) = temp_front; - printf("\n%d members load successfully.\n",count-1); - fclose(fp); - } - - - -} - -void csv_export(struct task *top,struct task *end){ - //save csv - FILE *fp; - char filename[SIZE]; - struct task *buffer = top; - char pot = '.'; - char c = 'c'; - char s = 's'; - char v = 'v'; - int count = 0; - printf("filename:"); - gets(filename); - count = strlen(filename); - - filename[count] = pot; - filename[count+1] = c; - filename[count+2] = s; - filename[count+3] = v; - filename[count+4] = '\0'; - printf("saving csv file %s\n",filename); - - if ((fp = fopen(filename,"w")) == NULL) - { - fprintf(stderr,"file %s cant not open.\n",filename); - } else { - if (buffer == NULL){ - printf("no data existed.\n"); - return; - } - count = 0; - while (buffer != (end->next)){ - fprintf(fp,"%d,%s,%s,%s,%d\n",buffer->id,buffer->name,buffer->mail,buffer->group,buffer->sex); - buffer = buffer->next; - printf("."); - count++; - } - printf("\n%d member saved successfully.\n",count); - printf("ファイルの書き込みが終わりました\n"); - fclose(fp); - } -} - -void txt_export(struct task *top,struct task *end){ - //save txt - FILE *fp; - char filename[SIZE]; - struct task *buffer = top; - char pot = '.'; - char t = 't'; - char x = 'x'; - int count = 0; - printf("filename:"); - gets(filename); - count = strlen(filename); - - filename[count] = pot; - filename[count+1] = t; - filename[count+2] = x; - filename[count+3] = t; - filename[count+4] = '\0'; - printf("saving txt file %s\n",filename); - - if ((fp = fopen(filename,"w")) == NULL) - { - fprintf(stderr,"file %s cant not open.\n",filename); - } else { - if (buffer == NULL){ - printf("no data existed.\n"); - return; - } - count = 0; - while (buffer != (end->next)){ - fprintf(fp,"%d %s %s %s %d \n",buffer->id,buffer->name,buffer->mail,buffer->group,buffer->sex); - buffer = buffer->next; - printf("."); - count++; - } - printf("\n%d member saved successfully.\n",count); - printf("ファイルの書き込みが終わりました\n"); - fclose(fp); - } -} - +#include +#include +#include +#include "functions.h" + +void csv_import(struct task **top, struct task **end){ + //load csv + FILE *fp; //ファイル宣言 + char filename[SIZE];//filename + printf("filename (csv format):"); + gets(filename);//input filename + struct task *temp = NULL; + int inputcode; + struct task *temp_front = NULL; + int id; + int count; + + int filename_count = 0; + char pot = '.'; + char slide = '/'; + char c = 'c'; + char s = 's'; + char v = 'v'; + filename_count = strlen(filename); + + filename[filename_count] = pot; + filename[filename_count+1] = c; + filename[filename_count+2] = s; + filename[filename_count+3] = v; + filename[filename_count+4] = '\0'; + printf("loading %s\n",filename); + + + if ((*top) == NULL){ + + count = 1; + printf("loading data from file...\n"); + temp = (struct task *)malloc(sizeof(struct task)); + temp->id = count; + (*top) = temp; + (*end) = temp; + + } else { + + printf("buffer data existed,(1)overwrite (2) write after existed data in file\n"); + inputcode = get_input(); + if (inputcode == 1){ + clear_list(&(*top),&(*end)); + (*top) = NULL; + (*end) = NULL; + (*top) = (struct task *)malloc(sizeof(struct task)); + temp = (*top); + (*end) = temp; + count = 1; + } else if (inputcode == 2){ + temp = (*top); + count = (*end)->id; + count++; + while(temp->next != NULL){ + temp = temp->next; + //count++; + } + } else { + printf("ERROR ,return to main menu.\n"); + return; + } + } + + if ((fp =fopen(filename,"r")) == NULL){ + fprintf(stderr,"file cannot be opened.\n"); + } else { + while(fscanf(fp,"%d,%[^,],%[^,],%[^,],%d\n",&id,temp->name,temp->mail,temp->group,&(temp->sex))!= EOF){ + temp-> id = count; + temp_front = temp; + temp->next = (struct task *)calloc(1,sizeof(struct task)); + temp = temp->next; + count++; + printf("."); + } + (*end) = temp_front; + printf("\n%d members load successfully.\n",count-1); + fclose(fp); + } +} + +void txt_import(struct task **top, struct task **end){ + //load txt + FILE *fp; //ファイル宣言 + char filename[SIZE];//filename + printf(" filename(txt format):"); + gets(filename);//input filename + struct task *temp = NULL; + int inputcode; + struct task *temp_front = NULL; + int count; + int id; + + int filename_count = 0; + char pot = '.'; + char t = 't'; + char x = 'x'; + filename_count = strlen(filename); + filename[filename_count] = pot; + filename[filename_count+1] = t; + filename[filename_count+2] = x; + filename[filename_count+3] = t; + filename[filename_count+4] = '\0'; + printf("loading %s\n",filename); + + if ((*top) == NULL){ + + count = 1; + printf("loading data from file...\n"); + temp = (struct task *)malloc(sizeof(struct task)); + temp->id = count; + (*top) = temp; + (*end) = temp; + + } else { + + printf("buffer data existed,(1)overwrite (2) write after existed data in file\n"); + inputcode = get_input(); + if (inputcode == 1){ + clear_list(&(*top),&(*end)); + (*top) = NULL; + (*end) = NULL; + (*top) = (struct task *)malloc(sizeof(struct task)); + temp = (*top); + (*end) = temp; + count = 1; + } else if (inputcode == 2){ + temp = (*top); + count = (*end)->id; + count++; + while(temp->next != NULL){ + temp = temp->next; + + } + } else { + printf("ERROR ,return to main menu.\n"); + return; + } + } + + if ((fp =fopen(filename,"r")) == NULL){ + fprintf(stderr,"file cannot be opened\n"); + } else { + while(fscanf(fp,"%d %s %s %s %d \n",&id,temp->name,temp->mail,temp->group,&(temp->sex))!= EOF){ + temp-> id = count; + temp_front = temp; + temp->next = (struct task *)calloc(1,sizeof(struct task)); + temp = temp->next; + count++; + printf("."); + } + (*end) = temp_front; + printf("\n%d members load successfully.\n",count-1); + fclose(fp); + } + + + +} + +void csv_export(struct task *top,struct task *end){ + //save csv + FILE *fp; + char filename[SIZE]; + struct task *buffer = top; + char pot = '.'; + char c = 'c'; + char s = 's'; + char v = 'v'; + int count = 0; + printf("filename:"); + gets(filename); + count = strlen(filename); + + filename[count] = pot; + filename[count+1] = c; + filename[count+2] = s; + filename[count+3] = v; + filename[count+4] = '\0'; + printf("saving csv file %s\n",filename); + + if ((fp = fopen(filename,"w")) == NULL) + { + fprintf(stderr,"file %s cant not open.\n",filename); + } else { + if (buffer == NULL){ + printf("no data existed.\n"); + return; + } + count = 0; + while (buffer != (end->next)){ + fprintf(fp,"%d,%s,%s,%s,%d\n",buffer->id,buffer->name,buffer->mail,buffer->group,buffer->sex); + buffer = buffer->next; + printf("."); + count++; + } + printf("\n%d member saved successfully.\n",count); + printf("file was written successfully.\n"); + fclose(fp); + } +} + +void txt_export(struct task *top,struct task *end){ + //save txt + FILE *fp; + char filename[SIZE]; + struct task *buffer = top; + char pot = '.'; + char t = 't'; + char x = 'x'; + int count = 0; + printf("filename:"); + gets(filename); + count = strlen(filename); + + filename[count] = pot; + filename[count+1] = t; + filename[count+2] = x; + filename[count+3] = t; + filename[count+4] = '\0'; + printf("saving txt file %s\n",filename); + + if ((fp = fopen(filename,"w")) == NULL) + { + fprintf(stderr,"file %s cant not open.\n",filename); + } else { + if (buffer == NULL){ + printf("no data existed.\n"); + return; + } + count = 0; + while (buffer != (end->next)){ + fprintf(fp,"%d %s %s %s %d \n",buffer->id,buffer->name,buffer->mail,buffer->group,buffer->sex); + buffer = buffer->next; + printf("."); + count++; + } + printf("\n%d member saved successfully.\n",count); + printf("file was written successfully\n"); + fclose(fp); + } +} + diff --git a/fdelete.c b/fdelete.c index 72a84a4..fd5c3bc 100644 --- a/fdelete.c +++ b/fdelete.c @@ -10,10 +10,10 @@ void fdelete(){ printf("file to delete:"); gets(filename);//input filename if((fp = fopen(filename, "w")) == NULL) { //ե"filename"ӳ - printf("ե뤬ҊĤޤ\n"); + printf("file was not found.\n"); } else { fprintf(fp," "); - printf("ե %s ޤ.\n",filename);//Ȥ + printf("file %s was deleted successfully.\n",filename);//Ȥ fclose(fp); //ե] } } diff --git a/find.c b/find.c index f6f0696..fe67f94 100644 --- a/find.c +++ b/find.c @@ -15,14 +15,14 @@ void update_name(struct task **top, struct task **end){ char sname[SIZE]; /*検索する名前*/ char nstr[SIZE]; - printf("編集したい名前を入力してください\n"); + printf("insert the name which you want to edit:\n"); scanf("%s",sname); while(p !=NULL){ if(strcmp(p->name,sname) == 0){ printf("%d,%s,%s,%s,%d\n", p->id,p->name,p->mail,p->group,p->sex); - printf("新しい名前を入力してください\n"); + printf("insert the new name:\n"); scanf("%s", nstr); strcpy(p->name,nstr); printf("%s\n",p->name); @@ -31,7 +31,7 @@ void update_name(struct task **top, struct task **end){ }else { p = p->next; if(p==NULL && cnt == 0){ - printf("見つかりませんでした\n"); + printf("can't find\n"); } } } @@ -50,14 +50,14 @@ void update_mail(struct task **top, struct task **end){ char sname[SIZE]; /*検索する名前*/ char nstr[SIZE]; - printf("編集したいメールアドレスを入力してください\n"); + printf("insert the mail you want to edit:\n"); scanf("%s",sname); while(p !=NULL){ if(strcmp(p->name,sname) == 0){ printf("%d,%s,%s,%s,%d\n", p->id,p->name,p->mail,p->group,p->sex); - printf("新しいメールアドレスを入力してください\n"); + printf("insert the new mail:\n"); scanf("%s", nstr); strcpy(p->name,nstr); printf("%s\n",p->name); @@ -66,7 +66,7 @@ void update_mail(struct task **top, struct task **end){ }else { p = p->next; if(p==NULL && cnt == 0){ - printf("見つかりませんでした\n"); + printf("can't find.\n"); } } } diff --git a/functions.h b/functions.h index ff89a41..40d1197 100644 --- a/functions.h +++ b/functions.h @@ -29,20 +29,27 @@ void code(struct task **top); void decode(struct task **top); void raw_import(struct task **top, struct task **end); void raw_export(struct task *top,struct task *end); -//sort.c +//cipher.c + +void update(struct task **head,struct task **end); +void update_mail(struct task **top, struct task **end); +//find.c +void swap(struct task *x, struct task *y); +void bubblesort_name(struct task s[], int len); +void bubblesort_group(struct task s[], int len); void az_sort(struct task **head,struct task **end); void group_sort(struct task **top, struct task **end); -void update(struct task **head,struct task **end); void group_sort(struct task **head, struct task **end); -void group_find(); +void group_find(struct task **top, struct task **end); void name_find(struct task **top, struct task **end); void sex_find(struct task **top, struct task **end); -//cipher.c +void id_find(struct task **top, struct task **end); +//sort.c void csv_import(struct task **top,struct task **end); void csv_export(struct task *top,struct task *end); void txt_import(struct task **top, struct task **end); void txt_export(struct task *top,struct task *end); //csv.c void fdelete(); -fdelete.c +//fdelete.c #endif diff --git a/main.c b/main.c index ac24d8b..c6481ff 100644 --- a/main.c +++ b/main.c @@ -1,255 +1,248 @@ -#include -#include -#include -//define basic headfiles -#include "functions.h" -//define custom headfiles - -int main(int argc,char const *argv[]) -{ - struct task *top = NULL; - struct task *end = NULL; - int filestatus; - int inputcode = -1; - int count; - - filestatus = 0;//check file status,0 = null,1 = exist - - - while (inputcode != 0) - { - printf(" * ******** ********\n"); - printf(" * * * * \n"); - printf(" * * * * \n"); - printf(" ******* * ********\n"); - printf(" * * * *\n"); - printf(" * * * *\n"); - printf("* * ******** ********\n"); - printf("\n\n------------------------------------------------\n\n"); - printf(" Welcome to Alpaca Contact System -0-\n\n\n"); - printf("(1)データ入力・追加\n"); - printf("(2)データ編集・erase\n"); - printf("(3)print input data(just add the sort system plz!)\n"); - printf("(4)save file\n"); - printf("(5)load file\n"); - printf("(6)delete data in file\n"); - printf("(7)output file to readable format\n"); - printf("(8)load file of readable format\n"); - printf("(9)exit\n"); - - - printf("\n\n************************************************\n\n"); - inputcode = get_input(); - if (inputcode == 1){ - if (filestatus == 0){ - printf("no data existed,do you want to create a new one?(y/n)\n "); - inputcode = get_input(); - if (inputcode == 1){ - add(&top,&end); - return_menu(); - filestatus = 1; - } - if (inputcode == 2){ - return_menu(); - } - - } else if (filestatus == 1){ - add(&top,&end); - return_menu(); - } - - } - //create new data - - else if (inputcode == 2){ - if (filestatus == 0){ - printf("no data existed.\n "); - return_menu(); - } - if (filestatus == 1){ - printf("it can't be restored,continue anyway?((1)y/(2)n)\n"); - inputcode = get_input(); - - if (inputcode == 1){ - printf("(1) edit (2) delete\n"); - inputcode = get_input(); - if (inputcode == 2){ - printf("1 for delete part of file, 2 for all\n"); - inputcode = get_input(); - if (inputcode == 1){ - printf("insert the id you want to delete\n"); - inputcode = get_input(); - delete_list(&top,&end,inputcode); - return_menu(); - if (top == NULL){ - filestatus = 0; - } - } else if (inputcode == 2){ - clear_list(&top,&end); - filestatus = 0; - return_menu(); - } - } else if (inputcode == 1){ - printf("(1)edit name (2)edit email\n"); - inputcode = get_input(); - if (inputcode == 1){ - update_name(&top,&end); - } else if (inputcode == 2){ - update_mail(&top,&end); - } else { - printf("wrong code!"); - } - return_menu(); - } - } else if (inputcode == 2){ - return_menu(); - } else { - printf("wrong code!"); - return_menu(); - } - - - } - } - //erase input data - else if (inputcode == 3){ - if (filestatus == 1){ - printf("(1)show all \n(2)search a member (search members of a group) \n(3)search all member in group \n"); - inputcode = get_input(); - if (inputcode == 1){ - printf("(1)sort by id \n(2)sort by name \n"); - inputcode = get_input(); - if (inputcode == 1){ - //sort by id - } - else if (inputcode == 2){ - az_sort(&top,&end); - - } else { - printf("wrong code!"); - return_menu(); - } - } else if (inputcode == 2){ - printf("(1)search by id \n(2)search by name \n(3)search by group \n(4)search by sex \n"); - inputcode = get_input(); - if (inputcode == 1){ - print_list(top,end); - } else if (inputcode == 2){ - name_find(&top,&end); - } else if (inputcode == 3){ - group_find(&top,&end); - } else if (inputcode == 4){ - printf("sort by sex\n"); - sex_find(&top,&end); - } - } else if (inputcode == 3){ - group_sort(&top,&end); - } - return_menu(); - } else if (filestatus == 0) { - printf("no data existed.\n"); - return_menu(); - } else { - printf("ERROR!\n"); - return_menu(); - } - - } - //print input data - else if (inputcode == 4){ - if (filestatus == 1){ - //file形式を変更する - csv_export(top,end); - return_menu(); - } else if (filestatus == 0){ - printf("no data existed.\n"); - return_menu(); - } - } - //save file - else if (inputcode == 5){ - raw_import(&top,&end); - return_menu(); - if (top != NULL){ - filestatus = 1; - } - } - //load file - else if (inputcode == 6){ - fdelete(); - return_menu(); - } - //delete data in file - else if (inputcode == 7){ - if (filestatus == 1){ - printf("(1)output file to csv format\n(2)output file to txt format\n"); - inputcode = get_input(); - if (inputcode == 2){ - txt_export(top,end); - return_menu(); - } else if (inputcode == 1){ - csv_export(top,end); - return_menu(); - } else { - printf("wrong code!\n"); - return_menu(); - } - } else if (filestatus == 0){ - printf("no data existed.\n"); - return_menu(); - } - } - //output file to readable format - else if (inputcode == 8){ - - printf("(1)load file to csv format\n(2)load file to txt format\n"); - inputcode = get_input(); - if (inputcode == 2){ - txt_import(&top,&end); - filestatus = 1; - return_menu(); - } else if (inputcode == 1){ - csv_import(&top,&end); - filestatus = 1; - return_menu(); - } else { - printf("wrong code!\n"); - return_menu(); - } - - //load file of readable format - } else if(inputcode == 9){ - printf("Thank you for using!\n"); - return 0; - } - - //exit - else { - printf("error! please insert correct control code."); - return_menu(); - } - - } - return 0; -} - -int get_input() -{ - int inputcode; - printf("insert inputcode:\n"); - scanf("%d",&inputcode); - getchar(); - return inputcode; -} - -void return_menu() -{ - char inputcode = ' '; - printf(" press q to continue;"); - while(inputcode != 'q'){ - inputcode = getchar(); - } - printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); -} - - +#include +#include +#include +//define basic headfiles +#include "functions.h" +//define custom headfiles + +int main(int argc,char const *argv[]) +{ + struct task *top = NULL; + struct task *end = NULL; + int filestatus = 0; + int inputcode = -1; + int count; + + + while (inputcode != 0) + { + printf(" * ******** ********\n"); + printf(" * * * * \n"); + printf(" * * * * \n"); + printf(" ******* * ********\n"); + printf(" * * * *\n"); + printf(" * * * *\n"); + printf("* * ******** ********\n"); + printf("\n\n------------------------------------------------\n\n"); + printf(" Welcome to Alpaca Contact System -0-\n\n\n"); + printf("(1)add new data\n"); + printf("(2)edit data\n"); + printf("(3)print input data\n"); + printf("(4)save file\n"); + printf("(5)load file\n"); + printf("(6)delete data in file\n"); + printf("(7)output file to readable format\n"); + printf("(8)load file of readable format\n"); + printf("(9)exit\n"); + + + printf("\n\n************************************************\n\n"); + inputcode = get_input(); + if (inputcode == 1){ + if (filestatus == 0){ + printf("no data existed,do you want to create a new one?(y/n)\n "); + inputcode = get_input(); + if (inputcode == 1){ + add(&top,&end); + return_menu(); + filestatus = 1; + } + if (inputcode == 2){ + return_menu(); + } + + } else if (filestatus == 1){ + add(&top,&end); + return_menu(); + } + + } + //create new data + + else if (inputcode == 2){ + if (filestatus == 0){ + printf("no data existed.\n "); + return_menu(); + } else if (filestatus == 1){ + printf("it can't be restored,continue anyway?((1)y/(2)n)\n"); + inputcode = get_input(); + + if (inputcode == 1){ + printf("(1) edit (2) delete\n"); + inputcode = get_input(); + if (inputcode == 2){ + printf("1 for delete part of file, 2 for all\n"); + inputcode = get_input(); + if (inputcode == 1){ + printf("insert the id you want to delete\n"); + inputcode = get_input(); + delete_list(&top,&end,inputcode); + return_menu(); + if (top == NULL){ + filestatus = 0; + } + } else if (inputcode == 2){ + clear_list(&top,&end); + filestatus = 0; + return_menu(); + } + } else if (inputcode == 1){ + printf("(1)edit name (2)edit email\n"); + inputcode = get_input(); + if (inputcode == 1){ + update_name(&top,&end); + } else if (inputcode == 2){ + update_mail(&top,&end); + } else { + printf("wrong code!"); + } + return_menu(); + } + } else if (inputcode == 2){ + return_menu(); + } else { + printf("wrong code!"); + return_menu(); + } + } + } + //erase input data + else if (inputcode == 3){ + if (filestatus == 1){ + printf("(1)show all \n(2)search a member (search members of a group) \n(3)search all member in group \n"); + inputcode = get_input(); + if (inputcode == 1){ + printf("(1)sort by id \n(2)sort by name \n"); + inputcode = get_input(); + if (inputcode == 1){ + print_list(top,end); + } else if (inputcode == 2){ + az_sort(&top,&end); + + } else { + printf("wrong code!"); + return_menu(); + } + } else if (inputcode == 2){ + printf("(1)search by id \n(2)search by name \n(3)search by group \n(4)search by sex \n"); + inputcode = get_input(); + if (inputcode == 1){ + id_find(&top,&end); + } else if (inputcode == 2){ + name_find(&top,&end); + } else if (inputcode == 3){ + group_find(&top,&end); + } else if (inputcode == 4){ + printf("sort by sex\n"); + sex_find(&top,&end); + } + } else if (inputcode == 3){ + group_sort(&top,&end); + } + return_menu(); + } else if (filestatus == 0) { + printf("no data existed.\n"); + return_menu(); + } else { + printf("ERROR!\n"); + return_menu(); + } + + } + //print input data + else if (inputcode == 4){ + if (filestatus == 1){ + raw_export(top,end); + return_menu(); + } else if (filestatus == 0){ + printf("no data existed.\n"); + return_menu(); + } + } + //save file + else if (inputcode == 5){ + raw_import(&top,&end); + return_menu(); + if (top != NULL){ + filestatus = 1; + } + } + //load file + else if (inputcode == 6){ + fdelete(); + return_menu(); + } + //delete data in file + else if (inputcode == 7){ + if (filestatus == 1){ + printf("(1)output file to csv format\n(2)output file to txt format\n"); + inputcode = get_input(); + if (inputcode == 2){ + txt_export(top,end); + return_menu(); + } else if (inputcode == 1){ + csv_export(top,end); + return_menu(); + } else { + printf("wrong code!\n"); + return_menu(); + } + } else if (filestatus == 0){ + printf("no data existed.\n"); + return_menu(); + } + } + //output file to readable format + else if (inputcode == 8){ + + printf("(1)load file to csv format\n(2)load file to txt format\n"); + inputcode = get_input(); + if (inputcode == 2){ + txt_import(&top,&end); + filestatus = 1; + return_menu(); + } else if (inputcode == 1){ + csv_import(&top,&end); + filestatus = 1; + return_menu(); + } else { + printf("wrong code!\n"); + return_menu(); + } + + //load file of readable format + } else if(inputcode == 9){ + printf("Thank you for using!\n"); + return 0; + } + + //exit + else { + printf("error! please insert correct control code."); + return_menu(); + } + + } + return 0; +} + +int get_input() +{ + int inputcode; + printf("insert inputcode:\n"); + scanf("%d",&inputcode); + getchar(); + return inputcode; +} + +void return_menu() +{ + char inputcode = ' '; + printf(" press q to continue;"); + while(inputcode != 'q'){ + inputcode = getchar(); + } + printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); +} + + diff --git a/sort.c b/sort.c index 5314b12..ea034c7 100644 --- a/sort.c +++ b/sort.c @@ -1,236 +1,274 @@ -#include -#include -#include -#include "functions.h" - - - -void swap(struct task *x, struct task *y){ -struct task temp = *x; - *x = *y; - *y = temp; -} - -void bubblesort_name(struct task s[], int len){ - - int i,j; - -for(i = 0;i0){ - swap(&s[j],&s[j+1]); - } - } - } -} - - -void bubblesort_group(struct task s[], int len){ - - int i,j; - -for(i = 0;i0){ - swap(&s[j],&s[j+1]); - } - } - } -} - - - -void az_sort(struct task **head, struct task **end ){ - - - struct task p[SIZE]; - struct task *q = *head; - - int i; - int len = 0; - char *temp; - - while(q!= ((*end)->next)){ - p[len] = (*q); - len++; - q = q->next; - - } - printf("%d\n", len); - - //printf("%d,%s,%s,%s,%d\n",p[7].id,p[7].name,p[7].mail,p[7].group,p[7].sex); - - bubblesort_name(p,len); - - // printf("%d,%s,%s,%s,%d\n",p[0].id,p[0].name,p[0].mail,p[0].group,p[0].sex); - - for(i = 0;inext; - - } - - bubblesort_group(p, len); - - int cnt = 1; - - printf("グループ毎に表示\n"); - - //printf("%s\n", p[1].group); - //printf("%d,%s,%s,%s,%d\n",p[0].group,p[0].id,p[0].name,p[0].mail,p[0].group,p[0].sex); - - for(i = 0;igroup,sname) != NULL){ - printf("%d,%s,%s,%s,%d\n", p->id,p->name,p->mail,p->group,p->sex); - p=p->next; - cnt = 1; - }else{ - p=p->next; - if(p==NULL && cnt == 0){ - printf("見つかりませんでした\n"); - } - } - } -} - - - - - - -void name_find(struct task **top, struct task **end){ - - int id; - char name[SIZE]; - char mail[SIZE]; - char group[SIZE]; - int sex; - - - struct task *p = *top; - struct task *q = *end; - - - - int cnt = 0; - char sname[SIZE]; /*検索する名前*/ - char xname[SIZE]; - - - - - - printf("名前を入力してください\n"); - scanf("%s",sname); - - while(p!= NULL){ - if(strstr(p->name,sname) != NULL){ - printf("%d,%s,%s,%s,%d\n", p->id,p->name,p->mail,p->group,p->sex); - p=p->next; - cnt = 1; - }else{ - p=p->next; - if(p==NULL && cnt == 0){ - printf("見つかりませんでした\n"); - } - } - } -} - - - -void sex_find(struct task **top, struct task **end){ - - int id; - char name[SIZE]; - char mail[SIZE]; - char group[SIZE]; - int sex; - - - - - - struct task *p = *top; - int cnt = 0; - char sname[SIZE]; /*検索する名前*/ - char xname[SIZE]; - - - - - printf("性別を入力してください(1は男性、2は女性で)\n"); - scanf("%d", &sex); - - - - - while(p!= NULL){ - if(p->sex == sex){ - printf("%d,%s,%s,%s,%d\n", p->id,p->name,p->mail,p->group,p->sex); - p=p->next; - }else{ - p=p->next; - } - } -} - - - +#include +#include +#include +#include "functions.h" + + + +void swap(struct task *x, struct task *y){ +struct task temp = *x; + *x = *y; + *y = temp; +} + +void bubblesort_name(struct task s[], int len){ + + int i,j; + +for(i = 0;i0){ + swap(&s[j],&s[j+1]); + } + } + } +} + + +void bubblesort_group(struct task s[], int len){ + + int i,j; + +for(i = 0;i0){ + swap(&s[j],&s[j+1]); + } + } + } +} + + + +void az_sort(struct task **head, struct task **end ){ + + + struct task p[SIZE]; + struct task *q = *head; + + int i; + int len = 0; + char *temp; + + while(q!= ((*end)->next)){ + p[len] = (*q); + len++; + q = q->next; + + } + printf("%d\n", len); + + //printf("%d,%s,%s,%s,%d\n",p[7].id,p[7].name,p[7].mail,p[7].group,p[7].sex); + + bubblesort_name(p,len); + + // printf("%d,%s,%s,%s,%d\n",p[0].id,p[0].name,p[0].mail,p[0].group,p[0].sex); + + for(i = 0;inext; + + } + + bubblesort_group(p, len); + + int cnt = 1; + + printf("print by group\n"); + + //printf("%s\n", p[1].group); + //printf("%d,%s,%s,%s,%d\n",p[0].group,p[0].id,p[0].name,p[0].mail,p[0].group,p[0].sex); + + for(i = 0;igroup,sname) != NULL){ + printf("%d,%s,%s,%s,%d\n", p->id,p->name,p->mail,p->group,p->sex); + p=p->next; + cnt = 1; + }else{ + p=p->next; + if(p==NULL && cnt == 0){ + printf("cannot find\n"); + } + } + } +} + + + + + + +void name_find(struct task **top, struct task **end){ + + int id; + char name[SIZE]; + char mail[SIZE]; + char group[SIZE]; + int sex; + + + struct task *p = *top; + struct task *q = *end; + + + + int cnt = 0; + char sname[SIZE]; /*検索する名前*/ + char xname[SIZE]; + + + + + + printf("insert name:\n"); + scanf("%s",sname); + + while(p!= NULL){ + if(strstr(p->name,sname) != NULL){ + printf("%d,%s,%s,%s,%d\n", p->id,p->name,p->mail,p->group,p->sex); + p=p->next; + cnt = 1; + }else{ + p=p->next; + if(p==NULL && cnt == 0){ + printf("cannot find\n"); + } + } + } +} + + + +void sex_find(struct task **top, struct task **end){ + + int id; + char name[SIZE]; + char mail[SIZE]; + char group[SIZE]; + int sex; + + + + + + struct task *p = *top; + int cnt = 0; + char sname[SIZE]; /*検索する名前*/ + char xname[SIZE]; + + + + + printf("insert sex:(1)male (2)female\n"); + scanf("%d", &sex); + + + + + while(p!= NULL){ + if(p->sex == sex){ + printf("%d,%s,%s,%s,%d\n", p->id,p->name,p->mail,p->group,p->sex); + p=p->next; + }else{ + p=p->next; + } + } +} + + + +void id_find(struct task **top, struct task **end){ + + int id; + char name[SIZE]; + char mail[SIZE]; + char group[SIZE]; + int sex; + + + struct task *p = *top; + struct task *q = *end; + + + + int cnt = 0; + int nid; + char xname[SIZE]; + + + + + + printf("insert id:\n"); + scanf("%d",&nid); + + while(p!= NULL){ + if((p->id) != nid){ + printf("%d,%s,%s,%s,%d\n", p->id,p->name,p->mail,p->group,p->sex); + p=p->next; + cnt = 1; + }else{ + p=p->next; + if(p==NULL && cnt == 0){ + printf("cannot find\n"); + } + } + } +}