c语言通讯录.docx
- 文档编号:4127674
- 上传时间:2022-11-28
- 格式:DOCX
- 页数:15
- 大小:16.20KB
c语言通讯录.docx
《c语言通讯录.docx》由会员分享,可在线阅读,更多相关《c语言通讯录.docx(15页珍藏版)》请在冰豆网上搜索。
c语言通讯录
#include
#include
#include
#defineFORMAT"%s\t\t%s\t\t%s\t%d\t%s\n"
intcount=0;
structid
{
charName[100];
intClass[100];
charaddress[100];
charqq[100];
charPhonNum[100];
};
intEnterface();
intAdd(idbook[]);
intModify(idbook[]);
intDelent(idbook[]);
intInsert(idbook[]);
intFind(idbook[]);
intShow(idbook[]);
intFindName(idbook[]);
intFindqq(idbook[]);
intDelName(idbook[]);
intDelqq(idbook[]);
intFindPhonNum(idbook[]);
intWritetxt(idbook[]);
intSearch(idbook[],charstr1[],intn);
intFSearch(idbook[],charstr2[],intn);
intTaxis(idbook[]);
intExit();
////////////////////////////////////////////////////////////////////
voidmain()
{
idbook[100];
intchoice;
inti,j;
charor='m';
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n");
printf("\n");
printf("!
!
!
欢迎使用班级通讯录系统!
!
!
\n");
printf("\n");
printf("!
!
!
按任意键进入系统!
!
!
\n");
printf("\n");
printf("\n");
printf("///////////////////////////////////////////////////////\n");
system("pause");
system("cls");
while(or=='m')
{
choice=Enterface();
switch(choice)
{
case1:
Add(book);
break;
case2:
Modify(book);
break;
case3:
Delent(book);
break;
case4:
Insert(book);
break;
case5:
Find(book);
break;
case6:
Show(book);
break;
case7:
Exit();
break;
default:
printf("!
!
!
输入错误!
!
!
\n");
Exit();
break;
}
}
}
intEnterface()
{
intchoice=0;
printf("*******************\n");
printf("1.添加\n");
printf("2.修改\n");
printf("3.删除\n");
printf("4.插入\n");
printf("5.查找\n");
printf("6.显示\n");
printf("7.退出\n");
printf("*******************\n");
printf("请输入您的选择:
");
scanf("%d",&choice);
returnchoice;
}
intAdd(idbook[])
{
charor='Y';
while('Y'==or)
{
printf("请输入姓名:
");
scanf("%s",&book[count].Name);
flag1:
printf("请输入电话号码:
");
scanf("%s",&book[count].PhonNum);
for(inti=0;i { if(strcmp(book[count].PhonNum,book[i].PhonNum)==0) { printf("! ! ! 号码已存在! ! ! \n"); gotoflag1; } } flag2: printf("请输入qq: "); scanf("%s",&book[count].qq); for(inti=0;i { if(strcmp(book[count].qq,book[i].qq)==0) { printf("! ! ! qq已存在! ! ! \n"); gotoflag2; } } printf("请输入Class: "); scanf("%d",&book[count].Class); printf("请输入地址: "); scanf("%s",&book[count].address); getchar(); count++; printf("是否继续添加('Y'添加,其他键返回主界面): "); scanf("%c",&or); if('Y'! =or) { system("cls"); break; } } Writetxt(book); return0; } intModify(idbook[]) { charstr[100]; intflag=0; intksd=0; inti; printf("去年个输入学号: "); scanf("%s",&str); for(i=0;i { if(strcmp(str,book[i].qq)==0) { if(ksd==0) { printf("姓名\t电话\t\tqq\tClass\t地址\n"); ksd=1; } printf("%8s\t%8s\t%s\t%d\t%s\n",book[i].Name,book[i].PhonNum, book[i].qq,book[i].Class,book[i].address); flag=1; break; } } if(flag==0) { printf("! ! ! 无此记录! ! ! \n"); return0; } printf("请输入姓名: "); scanf("%s",&book[i].Name); flag0: printf("请输入电话号码: "); scanf("%s",&book[i].PhonNum); for(intj=0;j { if(j==i) continue; if(strcmp(book[i].PhonNum,book[j].PhonNum)==0) { printf("! ! ! 号码已存在! ! ! \n"); gotoflag0; } } flag3: printf("请输入qq: "); scanf("%s",&book[i].qq); for(intj=0;j { if(j==i) continue; if(strcmp(book[i].qq,book[j].qq)==0) { printf("! ! ! qq已存在! ! ! \n"); gotoflag3; } } printf("请输入Class: "); scanf("%d",&book[i].Class); printf("请输入地址: "); scanf("%s",&book[i].address); getchar(); printf("修改完毕! \n"); Writetxt(book); system("pause"); return0; } intDelent(idbook[]) { intchoice=0; printf("================\n"); printf("1.按姓名删除\n"); printf("2.按qq删除\n"); printf("================\n"); scanf("%d",&choice); switch(choice) { case1: DelName(book); break; case2: Delqq(book); break; default: break; } return0; } intInsert(idbook[]) { Add(book); return0; } intFind(idbook[]) { intchoice=0; printf("================\n"); printf("1.按姓名查找\n"); printf("2.按qq查找\n"); printf("3.按电话查找\n"); printf("================\n"); scanf("%d",&choice); switch(choice) { case1: FindName(book); break; case2: Findqq(book); break; case3: FindPhonNum(book); break; default: break; } return0; } intFindName(id book[]) { charaname[100]; printf("请输入要查找的名字: "); scanf("%s",&aname); FSearch(book,aname,3); return0; } intFindqq(idbook[]) { charanum[100]; printf("请输入要查找的qq: "); scanf("%s",&anum); FSearch(book,anum,2); return0; } intFindPhonNum(idbook[]) { charaphonnum[100]; printf("请输入要查找的电话: "); scanf("%s",&aphonnum); FSearch(book,aphonnum,1); return0; } intShow(idbook[]) { intor=0; if(count==0) { printf("! ! ! 无记录! ! ! \n"); system("pause"); system("cls"); } else { printf("姓名\t电话\t\tqq\t班级\t地址\n"); for(inti=0;i printf("%8s\t%8s\t%s\t%d\t%s\n",book[i].Name,book[i].PhonNum, book[i].qq,book[i].Class,book[i].address); system("pause"); } printf("是否排序? \n-=1.排序=--=2.返回主界面=-\n"); scanf("%d",&or); if(1==or) return0; } intDelName(idbook[]) { charaname[100]; printf("请输入要删除的姓名: "); scanf("%s",&aname); Search(book,aname,2); return0; } intDelqq(idbook[]) { charanum[100]; printf("请输入要删除的qq: "); scanf("%s",&anum); Search(book,anum,1); return0; } intWritetxt(idbook[]) { FILE*fp; fp=fopen("photonumbers.txt","w"); for(inti=0;i { fprintf(fp,FORMAT,book[i].Name,book[i].PhonNum, book[i].qq,book[i].Class,book[i].address); } fclose(fp); return0; } intSearch(idbook[],charstr1[],intn) { intflag=0; intstr[5]; intflag_num=0; intj; intgf; intksd=0; for(inti=0;i { if(n==1) { if(strcmp(str1,book[i].qq)==0) flag=2; } elseif(n==2) { if(strcmp(str1,book[i].Name)==0) flag=2; } if(flag==2) { if(ksd==0) { printf("姓名\t电话\t\t学号\t班级\t地址\n"); ksd=1; } printf("%8s\t%8s\t%s\t%s\t%d\n",book[i].Name,book[i].PhonNum, book[i].qq,book[i].Class,book[i].address); str[flag_num++]=i; flag=1; } } if(flag==0) { printf("! ! ! 无记录! ! ! \n"); system("pause"); system("cls"); } if(flag==1) { printf("-=1.确认删除=-\t-=2.取消=-\n"); scanf("%d",&j); if(1==j) { gf=1; for(intm=str[0];m { for(intj=gf-1;j { if((m+gf)==str[j]) gf++; } strcpy(book[m].Name,book[m+gf].Name); book[m].Class=book[m+gf].Class; strcpy(book[m].qq,book[m+gf].qq); strcpy(book[m].PhonNum,book[m+gf].PhonNum); strcpy(book[m].address,book[m+gf].address); } count=count-flag_num; Writetxt(book); } elseif(2==j) { printf("! ! ! 操作已取消! ! ! \n"); } system("pause"); } return0; } intFSearch(idbook[],charstr2[],intn) { intflag=0; intksd=0; for(inti=0;i { if(n==1) { if(strcmp(str2,book[i].PhonNum)==0) flag=2; } elseif(3==n) { if(strcmp(str2,book[i].Name)==0) flag=2; } elseif(2==n) { if(strcmp(str2,book[i].qq)==0) flag=2; } if(flag==2) { if(0==ksd) { printf("姓名\t电话\t\tqq\t班级\t地址\n"); ksd=1; } printf("%8s\t%8s\t%s\t%s\t%d\n",book[i].Name,book[i].PhonNum, book[i].qq,book[i].Class,book[i].address); flag=1; } } if(1==flag) system("pause"); elseif(flag==0) { printf("! ! ! 无此记录! ! ! \n"); system("pause"); system("cls"); } return0; } intExit() { exit (1); return0; }
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 语言 通讯录