69,377
社区成员
发帖
与我相关
我的任务
分享
int substr(char *s1, char *s2, int len)
{
int i;
int p,j;
j=0;
for (i = 0; i < len; i++)
{
p = i;
if ((strchr(s2, s1[p])))//如果s2中存在字符s1[p],则为真
{
j++;
}
}
if(j>0)
{
return 1;
}
else
{
return 0;
}
}
//相对查找
void relatively_name(BOOK *head, char *sea)
{
BOOK *ptr;
int len;
char *bf1,*bf2,*bf3;
bf1 = (char *)malloc(32 * sizeof(char));
bf2 = (char *)malloc(32 * sizeof(char));
bf3 = (char *)malloc(32 * sizeof(char));
ptr = head;
len=strlen(sea);
while (ptr != NULL) //遍历链表
{
strcpy(bf1,ptr->name);
strcpy(bf2,ptr->phone);
strcpy(bf3,ptr->address);
if(substr(sea,bf1,len))
{
printf("%s\t%s\t%s\n", ptr->name, ptr->phone, ptr->address);
ptr = ptr->next;
}
else if(substr(sea,bf2,len))
{
printf("%s\t%s\t%s\n", ptr->name, ptr->phone, ptr->address);
ptr = ptr->next;
}
else if(substr(sea,bf3,len))
{
printf("%s\t%s\t%s\n", ptr->name, ptr->phone, ptr->address);
ptr = ptr->next;
}
else
{
ptr=ptr->next;
}
}
}