gpt4 book ai didi

c - 如何在结构的链表中搜索字符串以不仅首先找到所有出现的地方?

转载 作者:太空宇宙 更新时间:2023-11-04 04:40:13 25 4
gpt4 key购买 nike

如何在struct的链表中搜索string,不仅在最前面找到所有出现的地方?
我已经搜索了第一次出现并成功了任何人都可以帮忙吗?

struct employee{
int code;
char* name[50];
char* phone[20];
char* address[20];
int age;
float salary;

struct employee* next;
struct employee* prev;
};

struct employee* head;
struct employee* tail;

struct employee* find_address (char* name)
{
struct employee* temp = head;
while (temp && strcmp (temp->name, name))
{
temp = temp-> next;
}
return temp;
}

最佳答案

由于您的 find_address() 函数只能返回一个指向单个 employee 记录的指针,找到所有匹配项的唯一方法就是继续调用该函数,直到返回值等于 tail

关于c - 如何在结构的链表中搜索字符串以不仅首先找到所有出现的地方?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27195662/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com