#include <stdio.h>
#include <string.h>
#define MAX 100
struct telephone
{
char name[10];
char telno[20];
};
void search(struct telephone b[], char *x, int n);
void main()
{
struct telephone s[MAX];
int i=0;
char na[10],tel[20];
while(1)
{
printf("输入姓名:");
gets(na);
if(strcmp(na,"#")==0)
break;
printf("输入电话号码:");
gets(tel);
strcpy(s[i].name,na);
strcpy(s[i].telno,tel);
i++;
}
printf("查找的姓名:");
gets(na);
search(s,na,i);
}
void search(struct telephone b[],char *x,int n)
{
int i=0;
while(strcmp(b[i].name,x)!=0&&i<n)
i++;
if(i<n)
printf("电话号码是:%s\n",b[i].telno);
else
printf("没有找到!\n");
}
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交