结构体实现姓名电话查询
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#define MAX 101
struct pople{
char name[15];
int tel[15];
};
int readin(struct pople *s)
{
int i = 0, n = 0;
while(1)
{
scanf("%s",s[i].name);
if(!strcmp(s[i].name,"#"))
break;
scanf("%s",s[i].tel);
i++; n++;
}
return n;
}
int search(struct pople *s, char *x, int n)
{
for(int i=0; i<n; i++)
{
if(!strcmp(s[i].name,x))
{printf("name:%s tel:%s\n", x, s[i].tel); return 0;}
}
return 0;
}
int main()
{
struct pople a[101];
char name[15];
int num;
printf("please input name and phone:\n");
num = readin(a);
printf("input the name:");
scanf("%s", name);
search(a,name,num);
return 0;
}