#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct friends_list
{
char name[10];
int birthday;
char address[100];
char telephone[13];
};
int Count=0;
void new_friend(friends_list friends[]);
void search_friend(friends_list friends[ ],char*name);
void show_list(friends_list friends[]);
void delete_list(friends_list friends[]);
int main(void)
{
int choice;
char name[10];
friends_list friends[50];
system("color 08");
do{
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf(" **手机通讯录**\n");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf(" 选项1:新建\n");
printf(" 选项2:查询\n");
printf(" 选项3:显示全部\n");
printf(" 选项4:删除联系人\n");
printf(" 选项0:退出\n");
printf("请选择功能:");
scanf("%d",&choice);
switch(choice){
case 1:
new_friend(friends);
break;
case 2:
printf("请输入要查找的联系人姓名:");
scanf("%s",name);
search_friend(friends,name);
break;
case 3:
show_list(friends);
break;
case 4:
delete_list(friends);
break;
case 0:
break;
default: exit(0);
}
}while(choice != 0);
printf("谢谢使用通讯录功能!\n");
return 0;
}
void new_friend(struct friends_list friends[])
{
struct friends_list f;
if(Count == 50){
printf("通讯录已满!\n");
return;
}
printf("请输入新联系人的姓名:");
scanf("%s",f.name);
printf("请输入新联系人的生日:");
scanf("%d",&f.birthday);
printf("请输入新联系人的地址:");
scanf("%s",f.address);
printf("请输入新联系人的联系电话:");
scanf("%s",f.telephone);
friends[Count]=f;
Count ++;
}
void search_friend(struct friends_list friends[ ],char*name)
{
int i,flag=0;
if(Count==0){
printf(" 通讯录是空的\n");
return;
}
for(i=0;i<Count;i++)
if(strcmp(name,friends[i].name)==0){
flag=1;
break;
}
if(flag){
printf("姓名:%s\t\n",friends[i].name);
printf("生日:%d\t\n",friends[i].birthday);
printf("地址:%s\n",friends[i].address);
printf("电话:%s\n",friends[i].telephone);
}
else
printf(" 无此联系人\n");
}
void show_list(friends_list friends[])
{
int i;
for(i=0;i<Count;i++)
{printf("姓名:%s\t\n",friends[i].name);
printf("生日:%d\t\n",friends[i].birthday);
printf("地址:%s\n",friends[i].address);
printf("电话:%s\n",friends[i].telephone);}
}
void delete_list(friends_list friends[])
{
printf("功能正在完善中\n");
}