#include <stdio.h>
#include <string.h>
#define max 501
void start()
{
printf("当前通讯录最大容纳人数:%d。\n如需修改请修改源文件。\n",max-1);
}
struct tel
{
char name[10];
char num[20];
};
void input(struct tel *pttel1,int *counter)
{
int i,cmem1=0;
printf("请输入想创建的联系人人数:\n");
scanf("%d",&cmem1);
getchar();
for(i=0;i<cmem1;i++)
{
printf("新建联系人姓名:\n");
gets(pttel1->name);
printf("新建联系人电话:\n");
gets(pttel1->num);
}
counter+=cmem1;
}
void search(struct tel *pttel1,struct tel tel1)
{
int i,j,k,cmem2=0;
char name1[10];
printf("请输入想查找的联系人个数:\n");
scanf("%d",&cmem2);
getchar();
for(i=0;i<cmem2;i++)
{
printf("需查找的联系人姓名:\n");
gets(name1);
for(*pttel1=tel1;pttel1<&tel1+max;pttel1++)
{
if(strcmp(name1,pttel1->name)==0)
printf("您所查找的联系人为:%s\n其电话号码为%s\n",pttel1->name,pttel1->num);break;
}
printf("您查找的联系人不存在。\n通讯录中的联系人为:\n");
for(*pttel1=tel1;pttel1<&tel1+max;pttel1++)
printf("%s:%s\n",pttel1->name,pttel1->num);
}
}
int main()
{
start();
int choice,*counter,sum=0;
counter=∑
struct tel tel1[max];
struct tel *pttel1;
pttel1=tel1;
spawnpoint:printf("创建联系人输入\"1\",查找联系人输入\"2\",退出输入\"0\"。\n");
scanf("%d",&choice);
if(choice==1)
input(pttel1,counter);
else if(choice==2)
search(pttel1,tel1);
else if(choice==0)
return 0;
else
printf("错误\n");
goto spawnpoint;
}
求问哪写错了
编译器DevC++5.11
C:\Users\xbw\Desktop\未命名3.c In function 'main':
63 6 C:\Users\xbw\Desktop\未命名3.c [Error] incompatible type for argument 2 of 'search'
29 6 C:\Users\xbw\Desktop\未命名3.c [Note] expected 'struct tel' but argument is of type 'struct tel *'
tel1的类型是struct tel*,但是你search函数中参数2需要的是struct tel