c语言添加游客信息函数
时间: 2023-11-27 10:03:27 浏览: 37
好的,这里是一个简单的添加游客信息的函数示例:
```c
void add_tourist() {
if (num_tourists >= MAX_NUM_TOURISTS) {
printf("The system can only store up to %d tourists.\n", MAX_NUM_TOURISTS);
return;
}
Tourist new_tourist;
printf("Enter tourist name (max %d characters): ", MAX_NAME_LEN);
scanf("%s", new_tourist.name);
printf("Enter tourist age (1-%d): ", MAX_AGE);
scanf("%d", &new_tourist.age);
printf("Enter tourist phone number (max %d characters): ", MAX_PHONE_LEN);
scanf("%s", new_tourist.phone);
printf("Enter tourist email (max %d characters): ", MAX_EMAIL_LEN);
scanf("%s", new_tourist.email);
tourists[num_tourists] = new_tourist;
num_tourists++;
printf("Tourist added successfully.\n");
}
```
此函数会提示用户输入游客的姓名、年龄、电话号码和电子邮件地址,并将这些信息存储在一个 `Tourist` 结构体中。如果系统已经存储了最大数量的游客信息,则会显示一条错误消息并退出函数。否则,新的游客信息将被添加到 `tourists` 数组中,并将 `num_tourists` 计数器增加 1。最后,函数会显示一条成功消息。