diff --git a/未命名1.c b/未命名1.c index 7ee1068..f8a8a4b 100644 --- a/未命名1.c +++ b/未命名1.c @@ -33,12 +33,67 @@ void menu() printf("\t\t|\t g.˳ϵͳ |\n"); printf("\t\t|---------------------------------------------|\n"); } -int iCount; + void Rank() + { + FILE *fp; + void R_Save(struct student *phead); + fp=fopen("D:\\ѧϢ.txt","r"); + struct student *phead1=NULL; + struct student *pEnd1,*pNew1,*pNow1; + pNew1=(struct student*)malloc(sizeof(struct student)); + fscanf(fp,"%s",pNew1->id); + fscanf(fp,"%s",pNew1->name); + fscanf(fp,"%s",pNew1->sex); + fscanf(fp,"%d",&pNew1->age); + fscanf(fp,"%s",pNew1->note); + pNew1->next=NULL; + pEnd1=pNew1; + phead1=pNew1; + while(!feof(fp)) + { + pNew1=(struct student*)malloc(sizeof(struct student)); + fscanf(fp,"%s",pNew1->id); + fscanf(fp,"%s",pNew1->name); + fscanf(fp,"%s",pNew1->sex); + fscanf(fp,"%d",&pNew1->age); + fscanf(fp,"%s",pNew1->note); + pNew1->next=NULL; + pEnd1->next=pNew1; + pEnd1=pNew1; + } + pNow1 = phead1; + while(pNow1->next->next!=NULL) + { + pNow1 = pNow1->next; + } + pNow1->next=NULL; + fclose(fp); + struct student *i,*j,pTemp; + if(phead1 == NULL) + return; + for(i = phead1; i->next!=NULL;i = i->next) + { + for(j = phead1; j->next!=NULL; j = j->next) + { + if(strcmp(j->id , j->next->id)>0) + { + + strcpy(pTemp.id,j->id); strcpy(j->id,j->next->id); strcpy(j->next->id,pTemp.id); + strcpy(pTemp.name,j->name); strcpy(j->name,j->next->name); strcpy(j->next->name,pTemp.name); + strcpy(pTemp.sex,j->sex); strcpy(j->sex,j->next->sex); strcpy(j->next->sex,pTemp.sex); + strcpy(pTemp.note,j->note); strcpy(j->note,j->next->note); strcpy(j->next->note,pTemp.note); + pTemp.age=j->age; j->age=j->next->age; j->next->age=pTemp.age; + } + } + } + R_Save(phead1); + } + struct student* Create() { + /*void Save(struct student *phead);*/ struct student* phead=NULL; struct student *pEnd,*pNew; - iCount=0; pNew=(struct student*)malloc(sizeof(struct student)); printf("\t\t\t######ѧϢ######\n"); printf("\t\t\tѧţ"); scanf("%s",pNew->id); @@ -81,7 +136,9 @@ struct student* Create() fprintf(fp,"%s ",pTemp->note); pTemp=pTemp->next; } - } fclose(fp); + } + system("pause"); + fclose(fp); } void Print() @@ -99,7 +156,7 @@ void Print() printf("%s\n",a[1]); printf("Ա%s\n",a[2]); printf("䣻%d\n",b); - printf("ע%s\n",a[3]); + printf("ע%s\n\n",a[3]); fscanf(fp,"%s%s%s%d%s",a[0],a[1],a[2],&b,a[3]); } fclose(fp); @@ -111,7 +168,35 @@ void Save(struct student *phead) struct student *pTemp; pTemp=phead; FILE *fp; - if((fp=fopen("D:\\ѧϢ.txt","w"))!=NULL) + if(pTemp!=NULL) + { + if((fp=fopen("D:\\ѧϢ.txt","w"))!=NULL) + { + while(pTemp!=NULL) + { + fprintf(fp,"%s ",pTemp->id); + fprintf(fp,"%s ",pTemp->name); + fprintf(fp,"%s ",pTemp->sex); + fprintf(fp,"%d ",pTemp->age); + fprintf(fp,"%s ",pTemp->note); + pTemp=pTemp->next; + } + fclose(fp); + } + else + printf("ļʧ\n"); + } + Rank(); + system("pause"); +} +void R_Save(struct student *phead) +{ + struct student *pTemp; + pTemp=phead; + FILE *fp; + if(pTemp!=NULL) + { + if((fp=fopen("D:\\ѧϢ.txt","w"))!=NULL) { while(pTemp!=NULL) { @@ -123,14 +208,14 @@ void Save(struct student *phead) pTemp=pTemp->next; } fclose(fp); - return; } - else - printf("ļʧ"); + else + printf("ļʧ\n"); + } } struct student* Delete() { - char s[20]; int i=1; + char s[20]; struct student *pTemp,*pre; FILE *fp; fp=fopen("D:\\ѧϢ.txt","r"); @@ -163,16 +248,16 @@ struct student* Delete() pNow = pNow->next; } pNow->next=NULL; - pre=pTemp=phead; printf("\t\t\tѧţ"); - renew: scanf("%s",s); +renew: pre=pTemp=phead; int i=1; + scanf("%s",s); while(strcmp(pTemp->id,s)) { i++; pTemp=pTemp->next; if(pTemp==NULL) { - printf("\t\t\tѧ󣡣"); + printf("\t\t\tѧ󣡣\n"); printf("\t\t\t룺"); goto renew; } @@ -234,29 +319,29 @@ void search() } pNow->next=NULL; fclose(fp); - int x; char s[20]; + char x; char s[20]; printf("\t\t\tѡѯʽ\n1.ѧŲѯ\n2.ѯ\n3.Աѯ\n4.ѯ\n"); -RE: scanf("%d",&x); +RE: x=getch(); fflush(stdin); //ջ - pTemp=phead; int Y=0; +RE1: pTemp=phead; int Y=0; int flag = 1; switch(x) { - case 1: + case'1': printf("\t\t\tѧţ"); break; - case 2: + case'2': printf("\t\t\t"); break; - case 3: + case'3': printf("\t\t\tԱ"); break; - case 4: + case'4': printf("\t\t\t䣺"); scanf("%d",&Y); goto jump; break; default: - printf("\t\t\t\n\t\t\tѡ"); + printf("\t\t\t\n\t\t\tѡ\n"); goto RE; } scanf("%s",s); @@ -264,7 +349,7 @@ jump: while(pTemp!=NULL) { switch(x) { - case 1: + case'1': if(strcmp(s,pTemp->id)==0) { printf("ѧţ%s\n",pTemp->id); @@ -272,8 +357,10 @@ jump: while(pTemp!=NULL) printf("Ա%s\n",pTemp->sex); printf("䣻%d\n",pTemp->age); printf("ע%s\n",pTemp->note); - } break; - case 2: + flag = 0; + } + break; + case'2': if(strcmp(s,pTemp->name)==0) { printf("ѧţ%s\n",pTemp->id); @@ -281,8 +368,10 @@ jump: while(pTemp!=NULL) printf("Ա%s\n",pTemp->sex); printf("䣻%d\n",pTemp->age); printf("ע%s\n",pTemp->note); - } break; - case 3: + flag = 0; + } + break; + case'3': if(strcmp(s,pTemp->sex)==0) { printf("ѧţ%s\n",pTemp->id); @@ -290,8 +379,10 @@ jump: while(pTemp!=NULL) printf("Ա%s\n",pTemp->sex); printf("䣻%d\n",pTemp->age); printf("ע%s\n",pTemp->note); + flag = 0; } - case 4: + break; + case'4': if(Y==pTemp->age) { printf("ѧţ%s\n",pTemp->id); @@ -299,12 +390,17 @@ jump: while(pTemp!=NULL) printf("Ա%s\n",pTemp->sex); printf("䣻%d\n",pTemp->age); printf("ע%s\n",pTemp->note); - } break; - - + flag = 0; + } + break; } pTemp=pTemp->next; } + if(flag) + { + printf("\t\t\tδѯϢԣ\n"); + goto RE1; + } system("pause"); } @@ -342,23 +438,41 @@ struct student* Change() pNow = pNow->next; } pNow->next=NULL; - pTemp=phead; char s[20]; - printf("\t\t\tҪ޸ѧѧţ"); - scanf("%s",s); + char m[10]; int flag=1; +RE1: printf("\t\t\t룺 "); + scanf("%s",m); + if(strcmp(m,"123456")==0) + { +RE: pTemp=phead; + printf("\t\t\tҪ޸ѧѧţ"); + scanf("%s",s); while(pTemp!=NULL) { if(strcmp(s,pTemp->id)==0) { - printf("\t\t\tѧţ"); scanf("%s",pTemp->id); - printf("\t\t\t"); scanf("%s",pTemp->name); - printf("\t\t\tԱ"); scanf("%s",pTemp->sex); - printf("\t\t\t䣻"); scanf("%d",&pTemp->age); - printf("\t\t\tע"); scanf("%s",pTemp->note); + printf("\t\t\tѧţ%s\t\t\t޸ѧţ",pTemp->id); scanf("%s",pTemp->id); + printf("\t\t\t%s\t\t\t޸",pTemp->name); scanf("%s",pTemp->name); + printf("\t\t\tԱ%s\t\t\t޸Ա",pTemp->sex); scanf("%s",pTemp->sex); + printf("\t\t\t䣻%d\t\t\t޸䣺",pTemp->age); scanf("%d",&pTemp->age); + printf("\t\t\tע%s\t\t\t޸ıע",pTemp->note); scanf("%s",pTemp->note); + flag = 0; break; } pTemp=pTemp->next; } + } + else + { + printf("\t\t\t룡\n"); + goto RE1; + } + if(flag) + { + printf("\t\t\tѧ룡\n"); + goto RE; + } + system("pause"); fclose(fp); return phead; @@ -367,11 +481,11 @@ struct student* Change() int main() { - system("mode con cols=80 lines=30"); + /*system("mode con cols=80 lines=30");*/ system("color F5"); char x=0; char m[7]; - struct student *head; + struct student *head=NULL; Re: setposition(40,14); printf("룺 "); @@ -422,7 +536,8 @@ int main() } else { - printf("\t\t\tԣ\n"); + setposition(40,14); + printf("\t\t\t!\n"); // goto Re; } diff --git a/未命名1.exe b/未命名1.exe index ee827e9..0597f79 100644 Binary files a/未命名1.exe and b/未命名1.exe differ