求纠错!建立,查询,手机通讯录!实在不会纠正错误!求解,纠正时请讲解一下!谢了!!!
建立,查询,手机通讯录!实在不会纠正错误!求解,纠正时请讲解一下!谢了!!!建立手机通讯录,并查询联系人,查询时可通过联系人姓名,年龄或手机号码查询。
#include <stdio.h>
#include<string.h>
struct friends_list{
char name[10];
int age;
char telephone[13];
};
int count=0;
void new_friend(struct friends_list friends[]);
void search_friend(struct friends_list friends[],char*name);
void search_friend(struct friends_list friends[],int *age);
void search_friend(struct friends_list friends[],char *telephone);
int main(void)
{int choice,choice2;
char name[10];
struct friends_list friends[50];
do{
printf("手机通讯录功能选项:1:新建 2:查询 0:退出\n");
printf("请选择功能:");
scanf("%d",&choice);
switch(choice){
case 1:
new_friend(friends);
break;
case 2:
printf("请输入要查找的联系人的相关资料;1:姓名 2:年龄 3:号码 4:退出\n");
scanf("%d",&choice2);
switch(choice2)
{
case 1:
printf("请输入要查找的联系人姓名:");
scanf("%s",name);
search_friend(friends,name);
break;
case 2:
printf("请输入要查找的联系人的年龄\n");
scanf("%d",&age);
break;
case 3:
printf("请输入联系人的电话号码:\n");
scanf("%s",telephone);
search_friend(friends,telephone);
break;
}
case 0:
break;
}
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.name);
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",friends[i].name);
printf("年龄:%d\t",friends[i].age);
printf("电话:%s\n",friends[i].telephone);
}
else
printf("无此联系人!");
}
void search_friend(struct friends_list friends[],int *age)
{int j,f=0;if(count==0){
printf("通讯录为空~!!!\n");
return;
} for(j=0;j<count;j++)
if(strcmp(age,friends[j].age)==0)
{f=1;
break;
}
if(f){
printf("姓名:%s\t",friends[i].name);
printf("年龄:%d\t",friends[i].age);
printf("电话:%s\n",friends[i].telephone);
}
else printf("查无此人!!!!!!!!!!\n");
}
void search_friend(struct friends_list friends[],char *telephone){
int i,flog=0;if(count==0){
printf("通讯录为空!!!!!!!\n");
return;;
}
for(i=0;i<count;i++)
if(strcmp(telephone,friends[i].telephone)==0)
{flog=1;
break;
}
if(flog){
printf("姓名:%s\t",friends[i].name);
printf("年龄:%d\t",friends[i].age);
printf("电话:%s\n",friends[i].telephone);
}
else printf("查无此人!!!!!!!!!!\n");
}