#include<stdio.h>
#include<string.h>
struct friends_list{
char name[10];
int age;
char telephone[13];
};
int count=0;
void friends_new(struct friends_list friends[] );
void friends_search(struct friends_list friends[],char*name);
int main(void){
char name[10];
int choice;
struct friends_list friends[50];
do{
printf("[1新建],[2]查询,[0]退出.\n");
printf("请输入您的选择:");
scanf("%d",&choice);
switch(choice){
case 1:friends_new(friends);
break;
case 2:printf("请输入姓名:");
scanf("%s",name);
friends_search(friends,name);
break;
case 0:break;
}
}while(choice!=0);
printf("谢谢使用手机通讯录功能\n");
return 0;
}
void friends_new(struct friends_list friends[])
{
struct friends_list f;
if (count==50){
printf("通讯录已满\n");
return;
}
else{
printf("请输入姓名:");
scanf("%s",f.name);
printf("请输入年龄:");
scanf("%d",&f.age);
printf("请输入手机号:");
scanf("%s",f.telephone);
friends[count]=f;
count++;
return;
}
}
void friends_search(struct friends_list friends[],char*name)
{
if(count==0){
printf("通讯录为空\n");
return;
}
else{
int i,flag=0;
for(i=0;i<count;i++){
if(strcmp(name,friends[i].name)==0)
flag=1;
break;
}
if(flag){
printf("姓名%s\n",friends[i].name);
printf("年龄%d\n",friends[i].age);
printf("手机号%s\n",friends[i].telephone);
}
else {
printf("无此联系人\n");
}
return;
}
}