您好,欢迎访问三七文档
当前位置:首页 > 临时分类 > c语言程序设计——简单的通讯录系统(源代码)
#includestdio.h#includestring.h#includestdlib.h#includeconio.h#definesize50staticinth;staticcharkey[15];inti=0;structfriend_type{intnum;charname[10];chartel[13];charemail[15];charph[12];charQQ[10];charaddr[20];}fre[size];voidsave(){FILE*fp;inti;if((fp=fopen(friend.txt,wb))==NULL){printf(Cannotopenfile\n);return;}for(i=0;isize;i++)if(fwrite(&fre[i],sizeof(structfriend_type),1,fp)!=1)printf(filewriteerror\n);fclose(fp);}voidinput(){charch[10];inti=0;clrscr();printf(Areyousuretocreatinformation?(y/n)\n(ifyoupressy,theoldinformationwillbedeleted!)\n);scanf(%s,ch);if(strcmp(ch,y)==0||strcmp(ch,Y)==0){h=0;do{clrscr();printf(\nname:);scanf(%s,fre[i].name);printf(\ntelphonenumber:);scanf(%s,fre[i].tel);printf(\nmobilephonenumber:);scanf(%s,fre[i].ph);printf(\nemail:);scanf(%s,fre[i].email);printf(\nQQ:);scanf(%s,fre[i].QQ);printf(address:);scanf(%s,fre[i].addr);h++;i++;printf(\nifwantcontinueinputstudentinformation(y/n):);scanf(%s,ch);}while(strcmp(ch,y)==0||strcmp(ch,Y)==0);}save();}voidoutput(){intn=0;FILE*fp;clrscr();fp=fopen(friend.txt,rb);printf(nametelmobilephonee-mailQQaddress\n);do{fread(&fre[n],sizeof(structfriend_type),1,fp);printf(%-10s%-10s%-12s%-15s%-10s%-20s\n,fre[n].name,fre[n].tel,fre[n].ph,fre[n].email,fre[n].QQ,fre[n].addr);n++;}while(nh);fclose(fp);printf(Finished!Pressanykeytoreturn.);getch();}voidlook(){intn=0,a=0,i=0;charb[20];FILE*fp;clrscr();fp=fopen(friend.txt,rb);printf(\n\n\n\t\t\t1.searchbyname\n\t\t\t2.searchbytelephonenumber\n\t\t\t3.searchbymobilephonenumber\n\t\t\t4.returntomainmenu);printf(\n\nEnteryourchoice:);scanf(%d,&a);switch(a){case1:printf(\n);printf(\nenteryouwantlookname:);scanf(%s,b);do{if(strcmp(fre[n].name,b)==0){printf(nametelmobilephonee-mailQQaddress\n);printf(%-10s%-10s%-11s%-15s%-10s%-20s\n,fre[n].name,fre[n].tel,fre[n].ph,fre[n].email,fre[n].QQ,fre[n].addr);}n++;}while(nh);break;case2:printf(\n);printf(\nenteryouwantlooktelephonenumber:);scanf(%s,b);do{if(strcmp(fre[i].tel,b)==0){printf(nametelmobilephonee-mailQQaddress\n);printf(%-10s%-10s%-11s%-15s%-10s%-20s\n,fre[i].name,fre[i].tel,fre[i].ph,fre[i].email,fre[i].QQ,fre[i].addr);}i++;}while(ih);break;case3:printf(\n);printf(\nenteryouwantlookmobilephonenumber:);scanf(%s,b);do{if(strcmp(fre[n].ph,b)==0){printf(nametelmobilephonee-mailQQaddress\n);printf(%-10s%-10s%-11s%-15s%-10s%-20s\n,fre[n].name,fre[n].tel,fre[n].ph,fre[n].email,fre[n].QQ,fre[n].addr);}n++;}while(nh);break;case4:break;default:printf(Thechoiceisbetween1to3);sleep(1);look();}fclose(fp);printf(\nFinished!Pressanykeytoreturn.);getch();}voidchange(){intn=0;charch[20],a[20];FILE*fp;clrscr();fp=fopen(friend.txt,wb+);printf(\nenteryouwantchangename:);scanf(%s,a);do{if(strcmp(fre[n].name,a)==0){printf(nametelmobilephonee-mailQQaddress\n);printf(%-10s%-10s%-11s%-15s%-10s%-20s\n,fre[n].name,fre[n].tel,fre[n].ph,fre[n].email,fre[n].QQ,fre[n].addr);printf(\nyousurewantchangestudentname(y/n):);scanf(%s,ch);if(strcmp(ch,y)==0||strcmp(ch,Y)==0){printf(\nname:);scanf(%s,fre[n].name);}printf(\nyousurewantchangetelephonenumber(y/n):);scanf(%s,ch);if(strcmp(ch,y)==0||strcmp(ch,Y)==0){printf(\ntelephonenumber:);scanf(%s,fre[n].tel);}printf(\nyousurewantchangestudentmobilephonenumber(y/n):);scanf(%s,ch);if(strcmp(ch,y)==0||strcmp(ch,Y)==0){printf(\nmobilephonenumber:);scanf(%s,fre[n].ph);}printf(\nyousurewantchangestudente-mail(y/n):);scanf(%s,ch);if(strcmp(ch,y)==0||strcmp(ch,Y)==0){printf(\ne-mail:);scanf(%s,fre[n].email);}printf(\nyousurewantchangestudentQQ(y/n):);scanf(%s,ch);if(strcmp(ch,y)==0||strcmp(ch,Y)==0){printf(\nQQ:);scanf(%s,fre[n].QQ);}printf(\nyousurewantchangestudentaddress(y/n):);scanf(%s,ch);if(strcmp(ch,y)==0||strcmp(ch,Y)==0){printf(\naddress:);scanf(%s,fre[n].addr);}}n++;}while(nh);fclose(fp);printf(\nFinished!Pressanykeytoreturn.);getch();}voiddel(){inti,j;charc[20],ch[20];clrscr();printf(\nnameyouwanttodelete:);scanf(%s,c);for(i=0;ih;i++)if(strcmp(c,fre[i].name)==0)break;printf(\nyousurewantdelete(y/n):);scanf(%s,ch);if(strcmp(ch,y)==0||strcmp(ch,Y)==0){for(j=i;j=2;j++)fre[j]=fre[j+1];printf(\t\t\tyouhaddelete%s\n,c);h--;}printf(\nFinished!Pressanykeytoreturn.);getch();}voidadd(){inti=h;charch;clrscr();do{printf(\nname:);scanf(%s,fre[i].name);printf(\ntelphonenumber:);scanf(%s,fre[i].tel);printf(\nmobilephonenumber:);scanf(%s,fre[i].ph);printf(\nemail:);scanf(%s,fre[i].email);printf(\nQQ:);scanf(%s,fre[i].QQ);printf(address:);scanf(%s,fre[i].addr);h++;i++;printf(\nifwantcontinueinputstudentinformation(y/n):);scanf(%s,ch);}while(strcmp(ch,y)==0||strcmp(ch,Y)==0);}voidsave_h(){FILE*fp1;fp1=fopen(h.txt,wt);if(fp1==NULL){printf(Cannotopenfile\n);printf(Pressanykeytoreturn.\n);getch();}fputc(h,fp1);fclose(fp1);exit(0);}voidread_h(){FILE*fp1;fp1=fopen(h.txt,rt);h=fgetc(fp1);fclose(fp1);}voidsave_key(){chara[15],b[15],ch;FILE*fp2;fp2=fopen(key.txt,wt);clrscr();printf(\n\n\n\n\n\t\tAreyousuretochangethekey?(y/n)\n\t\t);scanf(%s,ch);if(strcmp(ch,y)==0||strcmp(ch,Y)==0){clrscr();printf(\n\n\n\n\n\t\t\tinputnewkey:);scanf(%s,a);printf(\n\n
本文标题:c语言程序设计——简单的通讯录系统(源代码)
链接地址:https://www.777doc.com/doc-2342418 .html