C语言编程问题用C语言编个学生通讯录管
小修改一下,如下:#include//通讯录#include#include#include#defineN100intM=0;structstudent{charnum[10];charname[10];chartel[12];};voidmyprint(){system("cls");printf("|-----------------------------------------------|\n");printf("|:-)请输入选项编号(0-7):|\n");printf("|-----------------------------------------------|\n"...全部
小修改一下,如下:#include//通讯录#include#include#include#defineN100intM=0;structstudent{charnum[10];charname[10];chartel[12];};voidmyprint(){system("cls");printf("|-----------------------------------------------|\n");printf("|:-)请输入选项编号(0-7):|\n");printf("|-----------------------------------------------|\n");printf("|--------------1--创建通讯录--------------------|\n");printf("|--------------2--显示通讯录--------------------|\n");printf("|--------------3--查询通讯录--------------------|\n");printf("|--------------4--修改通讯录--------------------|\n");printf("|--------------5--添加通讯录--------------------|\n");printf("|--------------6--删除通讯录--------------------|\n");printf("|--------------7--排序通讯录--------------------|\n");printf("|--------------0--退出--------------------------|\n");printf("|-----------------------------------------------|\n");}voidmycreat(structstudent*p,intn){structstudent*q=p;FILE*fp=NULL;fp=fopen("d:\\jilu。
dat","w");if(fp==NULL){printf("error,无法创建文件");return;}printf("\n初始创建,输入要创建同学的个数(后期可以添加):");do{scanf("%d",&M);}while(M9);n=M;for(p=q;p-qnum);}while(strcmp(p->num,"")==0);printf("姓名:");gets(p->name);printf("电话:");gets(p->tel);fprintf(fp,"%23s%15s%15s\n",p->num,p->name,p->tel);}}voidmydisplay(structstudent*p,intn){FILE*fp=NULL;fp=fopen("d:\\jilu。
dat","r");if(fp==NULL){printf("error");return;}system("cls");printf("%23s%15s%15s","学号","姓名","电话\n");while(n>0){fscanf(fp,"%23s%15s%15s",p->num,p->name,p->tel);printf("%23s%15s%15s\n",p->num,p->name,p->tel);p++;n--;}}voidmysearch(structstudent*p,intn){structstudent*q=p;intflag=0;charc='\0',nm[10]="",nam[10]="";printf("\n按照学号查询(h)或姓名查询(m):\n");c=getche();if(c=='h'||c=='H'){printf("请输入要查询记录的学号:");gets(nm);for(p=q;p-qnum)==0){printf("%23s%15s%15s","学号","姓名","电话\n");printf("%23s%15s%15s\n",p->num,p->name,p->tel);flag=1;}if(flag==0)printf("wrong。
。。\n");}elseif(c=='m'||c=='M'){printf("请输入要查询记录的姓名:");gets(nam);for(p=q;p-qname)==0){printf("%23s%15s%15s","学号","姓名","电话\n");printf("%23s%15s%15s\n",p->num,p->name,p->tel);flag=1;}if(flag==0)printf("wrong。
。。\n");}elseprintf("wrong。。。\n");}voidmymodify(structstudent*p,intn){structstudent*q=p;FILE*fp=NULL;charnam[10]="";mydisplay(p,n);printf("请输入您想要修改记录的姓名:\n");gets(nam);for(p=q;p-qname)==0)break;if(p-q==n)printf("wrong。
。。");else{printf("请输入正确的学号:");dogets(p->num);while(strcmp(p->num,"")==0);printf("请输入正确的姓名:");gets(p->name);printf("请输入正确的电话:");gets(p->tel);}fp=fopen("d:\\jilu。
dat","w");if(fp==NULL){printf("error");exit(0);}for(p=q;p-qnum,p->name,p->tel);fclose(fp);}voidmyadd(structstudent*p,intn){FILE*fp=NULL;structstudent*q=p;charc='\n',tempnum[10]="",tempname[10]="",temptel[10]="";printf("\n");while(strcmp(p->num,"")!=0){printf("%23s%15s%15s\n",p->num,p->name,p->tel);p++;}n=p-q;do{printf("请输入新同学的学号:");dogets(tempnum);while(strcmp(tempnum,"")==0);printf("请输入新同学的姓名:");gets(tempname);printf("请输入新同学的电话:");gets(temptel);for(p=q;p-qnum)==0||strcmp(temptel,p->tel)==0){printf("学号或电话号码需要重新输入吗(Y/N)?");c=getche();putchar('\n');break;}if(p-q==n){strcpy(p->num,tempnum);strcpy(p->name,tempname);strcpy(p->tel,temptel);break;}}while(c=='y'||c=='Y');fp=fopen("d:\\jilu。
dat","w");if(fp==NULL){printf("error");return;}for(p=q;p-qnum,p->name,p->tel);fclose(fp);M++;}voidmydelete(structstudent*p,intn){FILE*fp=NULL;structstudent*q=p;charc[10]="",tempnum[10]="",tempname[10]="",temptel[10]="",choose='\0';mydisplay(p,n);printf("选择删除记录的方式:学号(h)姓名(m)");choose=getche();printf("\n");if(choose=='m'||choose=='M'){printf("删除的记录:");gets(c);for(;p-qname)==0)break;if(p-qnum,(p+1)->num);strcpy(p->name,(p+1)->name);strcpy(p->tel,(p+1)->tel);}elseprintf("no\n");}elseif(choose=='h'||choose=='H'){printf("删除的记录:");gets(c);for(;p-qnum)==0)break;if(p-qnum,(p+1)->num);strcpy(p->name,(p+1)->name);strcpy(p->tel,(p+1)->tel);}elseprintf("no");}elseprintf("wrong\n");fp=fopen("d:\\jilu。
dat","w");if(fp==NULL){printf("error");return;}for(p=q;p-qnum,p->name,p->tel);fclose(fp);M--;}voidmysort(structstudent*p,intn){FILE*fp=NULL;structstudent*q=p,*w=p,*a=p;chartemp[10]="",c1='\0',c2='\0';mydisplay(p,n);printf("选择按照学号(h)或姓名(m)排序:\n");c1=getche();if(c1=='h'||c1=='H'){printf("升序(s)或者降序(j)排列:");c2=getche();if(c2=='s'||c2=='S')for(;p-anum,q->num)>0)w=q;strcpy(temp,w->num);strcpy(w->num,p->num);strcpy(p->num,temp);strcpy(temp,w->name);strcpy(w->name,p->name);strcpy(p->name,temp);strcpy(temp,w->tel);strcpy(w->tel,p->tel);strcpy(p->tel,temp);}elseif(c2=='j'||c2=='J')for(;p-anum,q->num)num);strcpy(w->num,p->num);strcpy(p->num,temp);strcpy(temp,w->name);strcpy(w->name,p->name);strcpy(p->name,temp);strcpy(temp,w->tel);strcpy(w->tel,p->tel);strcpy(p->tel,temp);}elseprintf("555wrong。
。。\n");}elseif(c1=='m'||c1=='M'){printf("升序(s)或者降序(j)排列:");c2=getche();if(c2=='s'||c2=='S')for(;p-aname,q->name)>0)w=q;strcpy(temp,w->num);strcpy(w->num,p->num);strcpy(p->num,temp);strcpy(temp,w->name);strcpy(w->name,p->name);strcpy(p->name,temp);strcpy(temp,w->tel);strcpy(w->tel,p->tel);strcpy(p->tel,temp);}elseif(c2=='j'||c2=='J')for(;p-aname,q->name)num);strcpy(w->num,p->num);strcpy(p->num,temp);strcpy(temp,w->name);strcpy(w->name,p->name);strcpy(p->name,temp);strcpy(temp,w->tel);strcpy(w->tel,p->tel);strcpy(p->tel,temp);}elseprintf("555wrong。
。。\n");}elseprintf("555wrong。。。\n");fp=fopen("d:\\jilu。dat","w");if(fp==NULL){printf("error");return;}for(p=a;p-anum,p->name,p->tel);fclose(fp);}main(){charchoose='\0',yes_no='\0';structstudentrecord[N]={0};do{myprint();printf(":-)请选择(0-7):");choose=getche();switch(choose){case'1':mycreat(record,M);break;case'2':mydisplay(record,M);break;case'3':mysearch(record,M);break;case'4':mymodify(record,M);break;case'5':myadd(record,M);break;case'6':mydelete(record,M);break;case'7':mysort(record,M);break;case'0':exit(0); ("\nerror。
。。
\n");}printf("\n:-)继续选择吗(y/n)?\n");do{yes_no=getch();}while(yes_no!='Y'&&yes_no!='y'&&yes_no!='N'&&yes_no!='n');}while(yes_no=='Y'||yes_no=='y');}。收起