通讯录源代码.docx
《通讯录源代码.docx》由会员分享,可在线阅读,更多相关《通讯录源代码.docx(20页珍藏版)》请在冰豆网上搜索。

通讯录源代码
通讯录源代码
#include#include#include#include#include#defineLENsizeof(structrecord)//计算字计//#defineNULL0
intnum;//通计计文件中的计系人计器数
structrecord
{
charname[100];
chargender[100];chartel[100];
charcity[100];
chareip[100];
structrecord*next;};
structrecord*head;voidmenu();//计示英文提示计计函数
voidcreat();//计建新的通计计
voidadd();//将某计系人增加到通计计中voidfind();//计合计计某计系人的通计信息voidalter();//修改通计计中某计系人的信息voiddeleteb();//计除通计计中某计系人的信息voidlist();//计示通计计中的所有计计voidsave();//用于计通计计的更新保存到文件中将
voidload();//计建新的通计计
voidquit(int*f);//退出计计
voidshifang();//计放存函明内数声
voidmain()
{
intchoic;
head=NULL;
intflag=1;
printf("使用计明:
在通计计中存在信息计每次使用通计计前计先加计通计计文件当!
\n");
while(flag)
{
menu();
scanf("%d",&choic);
switch(choic)
{
case1:
{
if(head==NULL)
creat();//计建
else
{
shifang();
creat();//重新计建
}
}
break;
case2:
{add();
save();//将追加的计计保存到文件中
}
break;
case3:
find();
printf("\t");
system("pause");//使系计计停
break;
case4:
{alter();
save();//将修改后的计计保存到文件中
}
printf("\t");
system("pause");
break;
case5:
deleteb();
printf("\t");
system("pause");
break;
case6:
load();break;
case7:
quit(&flag);break;
case8:
list();
printf("\t");
system("pause");
break;
}
}
}
voidmenu()
{
system("cls");
printf("\t\t\n");?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
printf("\t\t\n");※※
printf("\t\t※计迎使用通计计※\n");
printf("\t\t\n");※※
printf("\t\t1.※计建新的通计计2.增加计系人※\n");
printf("\t\t\n");※※
printf("\t\t3.※计计计系人信息4.修改计系人信息※\n");
printf("\t\t\n");※※
printf("\t\t5.※计除某计系人信息6.加计通计计文件※\n");printf("\t\t\n");※※
printf("\t\t7.※退出计计8.计示通计计中所有计计※\n");printf("\t\t\n");※※
printf("\t\t\n\n");?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
printf("\n\t\t计计入计计的操作您:
");
}
voidcreat()/*函数voidcreat()计建计系人的人信息个*/{
structrecord*p1,*p2;
charname[100];
num=0;
p1=head=(structrecord*)malloc(LEN);
p2=p1;
system("cls");
printf("计计入姓名~性计~计计~城市及计计(计束操作计按0号计)\n");
getchar();
printf("计入姓名:
");
gets(name);
if(strcmp(name,"0")!
=0&&name)
{
strcpy(p1->name,name);
printf("计入性计(男or女):
");
gets(p1->gender);
printf("计入8位计计计或号11位手机号(0-9):
");
gets(p1->tel);
printf("计入所在城市:
");
gets(p1->city);
printf("计入计计(0-9):
");
gets(p1->eip);
p1->next=NULL;
while
(1)
{
num=num+1;//通计计文件中的计系人计器增数1
if(num==1)
head=p1;
else
p2->next=p1;
p2=p1;
printf("计计入姓名:
");
gets(name);
if(strcmp(name,"0")==0)//当计入姓名计0计计表示此次计计计的计入计束
{
break;
}
else//计计计入
{
p1=(structrecord*)malloc(LEN);
strcpy(p1->name,name);
printf("计入性计(男or女):
");
gets(p1->gender);
printf("计入8位计计计或号11位手机号(0-9):
");
gets(p1->tel);
printf("计入所在城市:
");
gets(p1->city);
printf("计入计计(0-9):
");
gets(p1->eip);
p1->next=NULL;
}
}
p2->next=NULL;
save();
return;
}
else
return;
}
voidlist()//用于计出通计计中的所有计系人信息的函数
{
structrecord*p;
if(head!
=NULL)//通计计非空计~列出所有计系人信息
{system("cls");
p=head;
printf("本通计计计在共有%d人:
\n",num);
printf("---姓名-------性计------手机--------城市---------计计\n");
while(p!
=NULL)
{
printf("==%s",p->name);printf("");
printf("%s",p->gender);printf("");
printf("%s",p->tel);printf("");
printf("%s",p->city);printf("");
printf("%s",p->eip);printf("\n");
p=p->next;
}
printf("==================================\n");}
else//当通计计计空计~计出提示信息
printf("通计计计空,无法计出!
");
}
voidadd()//增加计计函数
{
structrecord*p0,*p1,*p2;
system("cls");//计行系计清屏
charname[100],ch;p1=head;
printf("计计入所要增加的计系人的各计信息:
\n");getchar();//吸收回计符或空格
printf("计计入姓名:
");
gets(name);
if((strcmp(name,"0")==0)&&name)
{
printf("姓名不能计0,增加失计!
\n");
return;
}
else
{
p0=(structrecord*)malloc(LEN);
strcpy(p0->name,name);
printf("计入性计(男or女):
");
gets(p0->gender);
printf("计入8位计计计或号11位手机号(0-9):
");
gets(p0->tel);
printf("计入所在城市:
");
gets(p0->city);
printf("计入计计(0-9):
");
gets(p0->eip);
num=num+1;
if(head==NULL)
{
head=p0;
p0->next=NULL;
return;
}
else
{
while(strcmp(p0->name,p1->name)>0&&(p1->next!
=NULL))//计计点所计添找
加的相计位置
{
p2=p1;
p1=p1->next;
}
if(strcmp(p0->name,p1->name)<0||strcmp(p0->name,p1->name)==0)//把计点
有序地增加到计表中
{
if(head==p1)
{
head=p0;//把计点添加到表计
}
else
{
p2->next=p0;
}
p0->next=p1;
}
else//把计点添加到表尾
{
p1->next=p0;
p0->next=NULL;
}
printf("\n是否计计添加?
(Y/N):
");
ch=getchar();
if((ch=='y')||(ch=='Y'))
add();
return;
}
}
}
voiddeleteb()//计除计计
{
system("cls");
structrecord*p,*q;
charsname[100],ch;
p=head;
if(head==NULL)
{
printf("通计计计空!
无法计除!
\n");
return;
}
printf("计计入欲计除计计的姓名:
");
scanf("%s",sname);
while(strcmp(p->name,sname)!
=0&&p->next!
=NULL)//计计点计除计计点找并
{
q=p;
p=p->next;
}
if(strcmp(p->name,sname)==0)
{
printf("%s的通计容如下内:
\n",sname);
printf("---姓名-------性计------手机--------城市---------计计\n");
printf("==================================\n");
printf("==%s",p->name);printf("");
printf("%s",p->gender);printf("");
printf("%s",p->tel);printf("");
printf("%s",p->city);printf("");
printf("%s",p->eip);printf("\n");
printf("==================================\n");
getchar();//吸收回计计和空格
printf("您确计要计除此人的通计计计计?
(Y/N):
");
ch=getchar();
if((ch=='Y')||(ch=='y'))
{
if(p==head)//当条通计计中只有一计计计
head=p->next;
else
q->next=p->next;
num=num-1;//通计计文件中的计系人计器数减1
printf("计除成功!
\n");
save();//保存到文件中
}
elseif((ch=='N')||(ch=='n'))
return;
}
else
{
printf("通计计中无此人信息,\n");
}
return;}
voidquit(int*f)//退出计计
{
*f=0;
printf("计计本次的使用您!
\n");
}
voidsave()//将写数通计计入文件的函
{
FILE*fp;
structrecord*p1;chartong[100];if(head==NULL)
{
fp=fopen("tongxun.txt","w");
fp=NULL;//将清通计计文件空
return;
}
getchar();//吸收回计计和空格
printf("计计入要保存通计计的文件名:
");gets(tong);
fp=fopen("tongxun.txt","w");
if(fp==NULL)
{
printf("打计通计计文件失计!
\n");
return;
}
p1=head;
fprintf(fp,"姓名性计手机城市计计\n");
for(;p1!
=NULL;){
fprintf(fp,"%s%s%s%s%s\n",p1->name,p1->gender,p1-
>tel,p1->city,p1->eip);
p1=p1->next;
}
printf("保存完计!
\n");
fclose(fp);
}
voidload()//文件加计函数
{
FILE*fp;
chartong[100];
structrecord*p1,*p2;system("cls");
getchar();
printf("正在加计通计计文件!
\n");getchar();
printf("计先计入要加计的通计计信息所在的文件名称:
");gets(tong);
if((fp=fopen("tongxun.txt","r"))==NULL)
{printf("此通计计名不存在,无法计出\n");return;
}
else
{
shifang();//计放存内
}
p1=(structrecord*)malloc(LEN);
fscanf(fp,"%s%s%s%s%s",&p1->name,&p1->gender,&p1->tel,&p1->city,&p1->eip);
if(feof(fp)!
=0)
{
printf("文件计空,无法打计!
\n");
return;
}
else
{
rewind(fp);
p2=p1;
head=p1;
num=0;
while(feof(fp)==0)
{
fscanf(fp,"%s%s%s%s%s",&p1->name,&p1->gender,&p1->tel,&p1-
>city,&p1->eip);
if(feof(fp)!
=0)
break;
p2->next=p1;
p2=p1;
p1=(structrecord*)malloc(LEN);
num=num+1;
}
p2->next=NULL;
p1=head;
head=head->next;
num=num-1;
free(p1);
list();//计示所有计计
printf("加计完计!
\n");
return;
}
fclose(fp);
}
voidshifang()//计放存函内数
{
structrecord*p1;while(head!
=NULL){
p1=head;
head=head->next;
free(p1);
}
return;
}
voidfindbyname()//按姓名计计某计系人的通计计信息
{
structrecord*p1,*p2;
charname[100];
intm;
system("cls");
if(head==NULL)
{
printf("通计计计空,无法计示!
\n");
return;
}
p1=head;
getchar();
printf("计计入需要计人的姓名找:
");
m=0;
gets(name);
while(p1!
=NULL)
{
while((strcmp(p1->name,name))!
=0&&p1->next!
=NULL)
{
p2=p1;
p1=p1->next;
}
if(strcmp(p1->name,name)==0)
{
m++;
printf("%s的通计容如下内:
\n",name);
printf("---姓名-------性计------手机--------城市---------计计\n");
printf("==================================\n");
printf("==%s",p1->name);printf("");
printf("%s",p1->gender);printf("");
printf("%s",p1->tel);printf("");
printf("%s",p1->city);printf("");
printf("%s",p1->eip);printf("\n");
printf("==================================\n");
printf("\n是否计计计某计系人的姓名信息找(Y/N):
");
if((getchar()=='y')||(getchar()=='Y'))
findbyname();
break;
}
p1=p1->next;
}
if(m==0)
printf("此人未在本通计计中!
\n");
return;
}
voidfindbytel()//按计计计计某计系人的通计计信息
{
structrecord*p1,*p2;
chartel[100];
intm;
system("cls");
if(head==NULL)
{
printf("通计计计空,无法计示!
\n");
return;
}
p1=head;
getchar();
printf("计计入需要计人的计计找:
");
m=0;
gets(tel);
while(p1!
=NULL)
{
while((strcmp(p1->tel,tel))!
=0&&p1->next!
=NULL)
{
p2=p1;
p1=p1->next;
}
if(strcmp(p1->tel,tel)==0)
{
m++;
printf("%s的通计容如下内:
\n",p1->name);
printf("---姓名-------性计------手机--------城市---------计计\n");
printf("==================================\n");
printf("==%s",p1->name);printf("");
printf("%s",p1->gender);printf("");
printf("%s",p1->tel);printf("");
printf("%s",p1->city);printf("");
printf("%s",p1->eip);printf("\n");
printf("==================================\n");
printf("\n是否计计计某计系人的计计信息找(Y/N):
");
if((getchar()=='y')||(getchar()=='Y'))
findbytel();
break;
}
p1=p1->next;
}
if(m==0)
printf("此人未在本通计计中!
\n");
return;
}
voidfind()
{
intm;
printf("\n计计计计计方式:
\n");
printf("\t1------姓名\n");
printf("\t2------计计\n");
printf("\t3------返回\n");
printf("计计计:
");
scanf("%d",&m);
while(m!
=1&&m!
=2&&m!
=3)
{
printf("计入计计~计重新计计:
");
scanf("%d",&m);
}
if(m==1)
findbyname();
if(m==2)
findbytel();}
voidaltertel()//修改计计计计{
structrecord*p;
inta=0;
charname[100];
system("cls");
getchar();
printf("计计入需要修改的计系人的姓名:
");
gets(name);
for(p=head;p!
=NULL;p=p->next)
{
if(strcmp(p->name,name)==0)
{
printf("%s的通计容如下内:
\n",name);
printf("---姓名-------性计------手机--------城市---------计计\n");
printf("==================================\n");
printf("==%s",p->name);printf("");
printf("%s",p->gender);printf("");
printf("%s",p->tel);printf("");
printf("%s",p->city);printf("");
printf("%s",p->eip);printf("\n");
printf("==================================\n");
printf("计计入新计计:
");
gets(p->tel);
printf("修改成功!
\n");
a=1;
break;
}
}
if(a!
=1)
printf("无此通计计,\n");
return;
}
voidaltereip(structrecord*p1)//修改计计信息
{
printf("计计入新计计:
");
gets(p1->eip);
}
voidaltercity()//修改城市信息
{
structrecord*p;
inta=0;
charname[100];
system("cls");
getchar();
printf("计计入需要修改的计系人的姓名:
");
gets(name);
for(p=head;p!
=NULL;p=p->next)
{
if(strcmp(p->name,name)==0)
{
printf("%s的通计容如下内:
\n",name);
printf("---姓名-------性计------手机--------城市