设计一个通讯录,里面有名字,微信号和电话号码,下面是我的程序
#include <stdio.h>
#include <string.h>
#define N 3
struct people
{
char name[10];
char weixin[15];
char phone[15];
}p[N];
int main()
{
void input(struct people p[]);
void input(struct people p[]);
struct people *find(struct peope p[],char str[]);
struct people *a;
char str[8];
input (p);
output (p);
printf("input finding name: ");
scanf("%s",str);
a=find(p,str);
if(a==NULL)
printf("not find\n");
else
printf("%-10s%-15d%-15c",a->name,a->weixin,a->phone);
return 0;
}
void input (struct people p[])
{
int i;
for(i=0;i<N;i++)
{
printf("input data of people %d:\n",i+1);
printf("name: ");
scanf("%s",p[i].name);
printf("wexin: ");
scanf("%d",p[i].wexin);
printf("phone: ");
scanf("%c",p[i].phone);
printf("\n");
}
}
void output (struct people p[])
{
int i;
printf("\n name weixin phone\n");
for(i=0;i<N;i++)
{
printf("%-10s%-15d%-15c",p[i].name,p[i].weixin,p[i].phone);
printf("\n");
}
}
struct people * find(struct people p[],char str[])
{
int i;
for(i=0;i<N;i++)
{
if(strcmp(str,p[i].name)==0)
return &p[i];
}
return NULL
}