commit 97c9adba4c2818bbf7de7f4f0ef9aee059bc6243 Author: 13187261606 <1013319022@qq.com> Date: Tue Jan 8 13:39:43 2019 +0800 123 diff --git a/未命名1.c b/未命名1.c new file mode 100644 index 0000000..20c8cfd --- /dev/null +++ b/未命名1.c @@ -0,0 +1,459 @@ +#include +#include +#include +#include +#include +struct student +{ + char id[12]; + char name[20]; + char sex[3]; + int age; + char note[100]; + struct student *next; +}; +void setposition(int x,int y) +{ + HANDLE win = GetStdHandle(STD_OUTPUT_HANDLE); + COORD pos = {x,y}; + SetConsoleCursorPosition(win,pos); +} + +void menu() +{ + system("cls"); + printf("\n\n\n\n\n"); + printf("\t\t|-------------༶ϵͳ----------------|\n"); + printf("\t\t|\t a.ѧϢ¼ |\n"); + printf("\t\t|\t b.ѧϢʾ |\n"); + printf("\t\t|\t c.ѧϢ |\n"); + printf("\t\t|\t d.ѧϢɾ |\n"); + printf("\t\t|\t e.ѧϢ޸ |\n"); + printf("\t\t|\t f.ѧϢѯ |\n"); + printf("\t\t|\t g.˳ϵͳ |\n"); + printf("\t\t|---------------------------------------------|\n"); + } +int iCount; +struct student* Create() +{ + 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); + printf("\t\t\t"); scanf("%s",pNew->name); + printf("\t\t\tԱ"); scanf("%s",pNew->sex); + printf("\t\t\t䣻"); scanf("%d",&pNew->age); + printf("\t\t\tע");scanf("%s",pNew->note); + pNew->next=NULL; + pEnd=pNew; + phead=pNew; + char key; + printf("\t\t\tǷ¼루y/⣩\n"); + key = getch(); + while(key=='y') + { + pNew=(struct student*)malloc(sizeof(struct student)); + printf("\t\t\t#####ѧϢ######\n"); + printf("\t\t\tѧţ"); scanf("%s",pNew->id); + printf("\t\t\t"); scanf("%s",pNew->name); + printf("\t\t\tԱ"); scanf("%s",pNew->sex); + printf("\t\t\t䣻"); scanf("%d",&pNew->age); + printf("\t\t\tע");scanf("%s",pNew->note); + pNew->next=NULL; + pEnd->next=pNew; + pEnd=pNew; + printf("\t\t\tǷ¼루y/⣩"); + key = getch(); + } + struct student *pTemp; + pTemp=phead; + FILE *fp; + if((fp=fopen("D:\\ѧϢ.txt","a"))!=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); +} + +void Print() +{ + printf("\t\t\t******ѧϢ*******\n"); + FILE *fp; + fp=fopen("D:\\ѧϢ.txt","r+"); + char a[4][100]; + int b; + fscanf(fp,"%s%s%s%d%s",a[0],a[1],a[2],&b,a[3]); + while(!feof(fp)) + { + + printf("ѧţ%s\n",a[0]); + printf("%s\n",a[1]); + printf("Ա%s\n",a[2]); + printf("䣻%d\n",b); + printf("ע%s\n",a[3]); + fscanf(fp,"%s%s%s%d%s",a[0],a[1],a[2],&b,a[3]); + } + fclose(fp); + system("pause"); +} + +void Save(struct student *phead) +{ + struct student *pTemp; + pTemp=phead; + FILE *fp; + 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); + return; + } + else + printf("ļʧ"); +} +struct student* Delete() +{ + char s[20]; int i=1; + struct student *pTemp,*pre; + FILE *fp; + fp=fopen("D:\\ѧϢ.txt","r"); + struct student *phead=NULL; + struct student *pEnd,*pNew,*pNow; + pNew=(struct student*)malloc(sizeof(struct student)); + fscanf(fp,"%s",pNew->id); + fscanf(fp,"%s",pNew->name); + fscanf(fp,"%s",pNew->sex); + fscanf(fp,"%d",&pNew->age); + fscanf(fp,"%s",pNew->note); + pNew->next=NULL; + pEnd=pNew; + phead=pNew; + while(!feof(fp)) + { + pNew=(struct student*)malloc(sizeof(struct student)); + fscanf(fp,"%s",pNew->id); + fscanf(fp,"%s",pNew->name); + fscanf(fp,"%s",pNew->sex); + fscanf(fp,"%d",&pNew->age); + fscanf(fp,"%s",pNew->note); + pNew->next=NULL; + pEnd->next=pNew; + pEnd=pNew; + } + pNow = phead; + while(pNow->next->next!=NULL) + { + pNow = pNow->next; + } + pNow->next=NULL; + pre=pTemp=phead; + printf("ѧţ"); + renew: scanf("%s",s); + while(strcmp(pTemp->id,s)) + { + i++; + pTemp=pTemp->next; + if(pTemp==NULL) + { + printf("ѧ󣡣"); + printf("룺"); + goto renew; + } + } + if(i>1) + { + pre=pTemp=phead; + int j; + for(j=1;jnext; + } + pre->next=pTemp->next; + free(pTemp); + } + else + { + pTemp=phead; + phead=phead->next; + free(pTemp); + } + fclose(fp); + system("pause"); + return phead; +} +void search() +{ + struct student *pTemp; + FILE *fp; + fp=fopen("D:\\ѧϢ.txt","r"); + struct student *phead=NULL; + struct student *pEnd,*pNew,*pNow; + pNew=(struct student*)malloc(sizeof(struct student)); + fscanf(fp,"%s",pNew->id); + fscanf(fp,"%s",pNew->name); + fscanf(fp,"%s",pNew->sex); + fscanf(fp,"%d",&pNew->age); + fscanf(fp,"%s",pNew->note); + pNew->next=NULL; + pEnd=pNew; + phead=pNew; + while(!feof(fp)) + { + pNew=(struct student*)malloc(sizeof(struct student)); + fscanf(fp,"%s",pNew->id); + fscanf(fp,"%s",pNew->name); + fscanf(fp,"%s",pNew->sex); + fscanf(fp,"%d",&pNew->age); + fscanf(fp,"%s",pNew->note); + pNew->next=NULL; + pEnd->next=pNew; + pEnd=pNew; + } + pNow = phead; + while(pNow->next->next!=NULL) + { + pNow = pNow->next; + } + pNow->next=NULL; + fclose(fp); + int x; char s[20]; + printf("\t\t\tѡѯʽ\n1.ѧŲѯ\n2.ѯ\n3.Աѯ\n4.ѯ\n"); +RE: scanf("%d",&x); + pTemp=phead; int Y=0; + switch(x) + { + case 1: + printf("\t\t\tѧţ"); + break; + case 2: + printf("\t\t\t"); + break; + case 3: + printf("\t\t\tԱ"); + break; + case 4: + printf("\t\t\t䣺"); + scanf("%d",&Y); + goto jump; + break; + default: + printf("\t\t\t\n\t\t\tѡ"); + goto RE; + } + scanf("%s",s); +jump: while(pTemp!=NULL) + { + switch(x) + { + case 1: + if(strcmp(s,pTemp->id)==0) + { + printf("ѧţ%s\n",pTemp->id); + printf("%s\n",pTemp->name); + printf("Ա%s\n",pTemp->sex); + printf("䣻%d\n",pTemp->age); + printf("ע%s\n",pTemp->note); + } break; + case 2: + if(strcmp(s,pTemp->name)==0) + { + printf("ѧţ%s\n",pTemp->id); + printf("%s\n",pTemp->name); + printf("Ա%s\n",pTemp->sex); + printf("䣻%d\n",pTemp->age); + printf("ע%s\n",pTemp->note); + } break; + case 3: + if(strcmp(s,pTemp->sex)==0) + { + printf("ѧţ%s\n",pTemp->id); + printf("%s\n",pTemp->name); + printf("Ա%s\n",pTemp->sex); + printf("䣻%d\n",pTemp->age); + printf("ע%s\n",pTemp->note); + } + case 4: + if(Y==pTemp->age) + { + printf("ѧţ%s\n",pTemp->id); + printf("%s\n",pTemp->name); + printf("Ա%s\n",pTemp->sex); + printf("䣻%d\n",pTemp->age); + printf("ע%s\n",pTemp->note); + } break; + + + } + pTemp=pTemp->next; + } + system("pause"); + +} +struct student* Change() +{ + struct student *pTemp; + FILE *fp; + fp=fopen("D:\\ѧϢ.txt","r"); + struct student *phead=NULL; + struct student *pEnd,*pNew,*pNow; + pNew=(struct student*)malloc(sizeof(struct student)); + fscanf(fp,"%s",pNew->id); + fscanf(fp,"%s",pNew->name); + fscanf(fp,"%s",pNew->sex); + fscanf(fp,"%d",&pNew->age); + fscanf(fp,"%s",pNew->note); + pNew->next=NULL; + pEnd=pNew; + phead=pNew; + while(!feof(fp)) + { + pNew=(struct student*)malloc(sizeof(struct student)); + fscanf(fp,"%s",pNew->id); + fscanf(fp,"%s",pNew->name); + fscanf(fp,"%s",pNew->sex); + fscanf(fp,"%d",&pNew->age); + fscanf(fp,"%s",pNew->note); + pNew->next=NULL; + pEnd->next=pNew; + pEnd=pNew; + } + pNow = phead; + while(pNow->next->next!=NULL) + { + pNow = pNow->next; + } + pNow->next=NULL; + pTemp=phead; + char s[20]; + printf("Ҫ޸ѧѧţ"); + 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); + break; + } + pTemp=pTemp->next; + } + system("pause"); + fclose(fp); + return phead; + + } + +int main() +{ + system("color F5"); + char x=0; + char m[7]; + struct student *head; + Re: + setposition(40,14); + printf("룺 "); + setposition(39,13); + printf("*********************"); + setposition(39,15); + printf("*********************"); + setposition(39,14); + printf("*"); + setposition(59,14); + printf("*"); + setposition(51,14); + scanf("%s",m); + if(strcmp(m,"aaaaaa")==0) + { + + while(1) + { + + + if(x=='g') + exit(0); + switch(x) + { + case'a': + Create(); + break; + case'b': + Print(); + break; + case'c': + Save(head); + break; + case'd': + head=Delete(); + break; + case'e': + head=Change(); + break; + case'f': + search(); + break; + } + menu(); + printf("\t\t\tѡҪִеIJ"); + scanf("%c",&x); + } + } + else + { + printf("ԣ\n"); + goto Re; + } + + return 0; +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/未命名1.exe b/未命名1.exe new file mode 100644 index 0000000..6c96c6b Binary files /dev/null and b/未命名1.exe differ