删除游客信息函数
时间: 2023-11-17 11:05:32 浏览: 26
好的,下面是一个简单的删除游客信息的函数示例:
```c
void delete_tourist() {
if (num_tourists == 0) {
printf("No tourists found in the system.\n");
return;
}
int index;
printf("Enter the index of the tourist to be deleted (0-%d): ", num_tourists - 1);
scanf("%d", &index);
if (index < 0 || index >= num_tourists) {
printf("Invalid index. Please enter a number between 0 and %d.\n", num_tourists - 1);
return;
}
Tourist deleted_tourist = tourists[index];
for (int i = index; i < num_tourists - 1; i++) {
tourists[i] = tourists[i + 1];
}
num_tourists--;
printf("Tourist \"%s\" has been deleted.\n", deleted_tourist.name);
}
```
此函数会提示用户输入要删除的游客的索引,然后将该游客从 `tourists` 数组中删除。如果系统中没有任何游客信息,则会显示一条错误消息并退出函数。如果输入的索引无效,则会显示一条错误消息并退出函数。否则,该函数将从 `tourists` 数组中删除指定的游客信息,并将 `num_tourists` 计数器减少 1。最后,函数会显示一条成功消息。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![application/msword](https://img-home.csdnimg.cn/images/20210720083327.png)
![cpp](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)