查找游客信息函数
时间: 2023-10-18 22:18:16 浏览: 47
好的,下面是一个简单的查找游客信息的函数示例:
```c
void find_tourist() {
if (num_tourists == 0) {
printf("No tourists found in the system.\n");
return;
}
char search_name[MAX_NAME_LEN + 1];
printf("Enter the name of the tourist to be found (max %d characters): ", MAX_NAME_LEN);
scanf("%s", search_name);
int found_index = -1;
for (int i = 0; i < num_tourists; i++) {
if (strcmp(tourists[i].name, search_name) == 0) {
found_index = i;
break;
}
}
if (found_index == -1) {
printf("Tourist \"%s\" not found in the system.\n", search_name);
return;
}
Tourist found_tourist = tourists[found_index];
printf("Tourist found at index %d:\n", found_index);
printf("Name: %s\n", found_tourist.name);
printf("Age: %d\n", found_tourist.age);
printf("Phone: %s\n", found_tourist.phone);
printf("Email: %s\n", found_tourist.email);
}
```
此函数会提示用户输入要查找的游客的姓名,并在 `tourists` 数组中查找该游客。如果系统中没有任何游客信息,则会显示一条错误消息并退出函数。如果输入的姓名不匹配任何游客,则会显示一条错误消息并退出函数。否则,该函数将显示找到的游客的信息。