C语言实现Windows环境下志愿者服务活动管理系统:含录入、查询、修改功能
好的,下面是一个志愿者服务活动信息管理系统的C语言实现。这个系统包括菜单驱动的用户界面,可以录入、浏览、查询和修改志愿者服务活动信息。 代码实现 ```c #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_NAME_LEN 50 #define MAX_PHONE_LEN 15 #define MAX_ACTIVITY_NAME_LEN 50 #define MAX_LOCATION_LEN 100 #define MAX_CONTENT_LEN 200 #define FILE_NAME "volunteer_info.dat" typedef struct { char name[MAX_NAME_LEN]; char phone[MAX_PHONE_LEN]; char activityName[MAX_ACTIVITY_NAME_LEN]; char location[MAX_LOCATION_LEN]; char content[MAX_CONTENT_LEN]; } VolunteerInfo; void displayMenu(); void addVolunteerInfo(); void viewVolunteerInfo(); void searchVolunteerInfoByName(); void searchVolunteerInfoByPhone(); void deleteVolunteerInfo(); void modifyVolunteerInfo(); void loadData(VolunteerInfo *info, int *count); void saveData(VolunteerInfo *info, int count); int main() { int choice; do { displayMenu(); printf("请输入您的选择: "); scanf("%d", &choice); getchar(); // 清除缓冲区中的换行符 switch (choice) { case 1: addVolunteerInfo(); break; case 2: viewVolunteerInfo(); break; case 3: searchVolunteerInfoByName(); break; case 4: searchVolunteerInfoByPhone(); break; case 5: deleteVolunteerInfo(); break; case 6: modifyVolunteerInfo(); break; case 7: printf("退出系统\n"); break; default: printf("无效的选择,请重新输入\n"); } } while (choice != 7); return 0; } void displayMenu() { printf("\n=== 志愿者服务活动信息管理系统 ===\n"); printf("1. 录入志愿者服务活动信息\n"); printf("2. 浏览志愿者服务活动信息\n"); printf("3. 按志愿者姓名查询\n"); printf("4. 按手机号查询\n"); printf("5. 删除志愿者服务活动信息\n"); printf("6. 修改志愿者服务活动信息\n"); printf("7. 退出系统\n"); } void addVolunteerInfo() { VolunteerInfo info; printf("请输入志愿者姓名: "); fgets(info.name, MAX_NAME_LEN, stdin); info.name[strcspn(info.name, "\n")] = '\0'; // 去除换行符 printf("请输入志愿者电话: "); fgets(info.phone, MAX_PHONE_LEN, stdin); info.phone[strcspn(info.phone, "\n")] = '\0'; // 去除换行符 printf("请输入服务活动名称: "); fgets(info.activityName, MAX_ACTIVITY_NAME_LEN, stdin); info.activityName[strcspn(info.activityName, "\n")] = '\0'; // 去除换行符 printf("请输入地点: "); fgets(info.location, MAX_LOCATION_LEN, stdin); info.location[strcspn(info.location, "\n")] = '\0'; // 去除换行符 printf("请输入内容: "); fgets(info.content, MAX_CONTENT_LEN, stdin); info.content[strcspn(info.content, "\n")] = '\0'; // 去除换行符 FILE *file = fopen(FILE_NAME, "ab"); if (file == NULL) { perror("无法打开文件"); return; } fwrite(&info, sizeof(VolunteerInfo), 1, file); fclose(file); printf("信息录入成功\n"); } void viewVolunteerInfo() { FILE *file = fopen(FILE_NAME, "rb"); if (file == NULL) { perror("无法打开文件"); return; } VolunteerInfo info; while (fread(&info, sizeof(VolunteerInfo), 1, file)) { printf("\n志愿者姓名: %s\n", info.name); printf("志愿者电话: %s\n", info.phone); printf("服务活动名称: %s\n", info.activityName); printf("地点: %s\n", info.location); printf("内容: %s\n", info.content); } fclose(file); } void searchVolunteerInfoByName() { char name[MAX_NAME_LEN]; printf("请输入要查询的志愿者姓名: "); fgets(name, MAX_NAME_LEN, stdin); name[strcspn(name, "\n")] = '\0'; // 去除换行符 FILE *file = fopen(FILE_NAME, "rb"); if (file == NULL) { perror("无法打开文件"); return; } VolunteerInfo info; int found = 0; while (fread(&info, sizeof(VolunteerInfo), 1, file)) { if (strcmp(info.name, name) == 0) { printf("\n志愿者姓名: %s\n", info.name); printf("志愿者电话: %s\n", info.phone); printf("服务活动名称: %s\n", info.activityName); printf("地点: %s\n", info.location); printf("内容: %s\n", info.content); found = 1; } } if (!found) { printf("未找到匹配的志愿者信息\n"); } fclose(file); } void searchVolunteerInfoByPhone() { char phone[MAX_PHONE_LEN]; printf("请输入要查询的志愿者电话: "); fgets(phone, MAX_PHONE_LEN, stdin); phone[strcspn(phone, "\n")] = '\0'; // 去除换行符 FILE *file = fopen(FILE_NAME, "rb"); if (file == NULL) { perror("无法打开文件"); return; } VolunteerInfo info; int found = 0; while (fread(&info, sizeof(VolunteerInfo), 1, file)) { if (strcmp(info.phone, phone) == 0) { printf("\n志愿者姓名: %s\n", info.name); printf("志愿者电话: %s\n", info.phone); printf("服务活动名称: %s\n", info.activityName); printf("地点: %s\n", info.location); printf("内容: %s\n", info.content); found = 1; } } if (!found) { printf("未找到匹配的志愿者信息\n"); } fclose(file); } void deleteVolunteerInfo() { char name[MAX_NAME_LEN]; printf("请输入要删除的志愿者姓名: "); fgets(name, MAX_NAME_LEN, stdin); name[strcspn(name, "\n")] = '\0'; // 去除换行符 FILE *file = fopen(FILE_NAME, "rb"); if (file == NULL) { perror("无法打开文件"); return; } VolunteerInfo info; VolunteerInfo temp[100]; // 假设最多有100条记录,可以根据需要调整大小或动态分配内存 int count = 0; while (fread(&info, sizeof(VolunteerInfo), 1, file)) { if (strcmp(info.name, name) != 0) { temp ######[AI写代码神器 | 2048点数解答 | 2025-03-03 21:04:32]
- Python 实现简易密码设置系统:多种功能交互与安全要点揭秘(字节豆包 | 286点数解答 | 2025-03-28 10:43:21)356
- C语言实现多功能密码设置系统:含代码及安全注意要点(字节豆包 | 414点数解答 | 2025-03-28 10:43:55)347
- C 语言实现:超简单密码设置系统,含代码与注意要点!(字节豆包 | 519点数解答 | 2025-03-28 12:42:02)386
- C语言实现密码管理系统:含功能代码与安全注意事项(字节豆包 | 409点数解答 | 2025-04-05 18:09:56)333
- C语言实现多功能密码系统:初始化、确认、设置、显示、重置与退出(字节豆包 | 454点数解答 | 2025-04-05 18:48:42)333
- C语言实现密码管理系统:含初始化、确认、设置、显示、重置及退出功能(字节豆包 | 413点数解答 | 2025-04-06 15:37:16)280
- C 语言实现密码管理系统:含初始化、确认、设置、显示、重置及退出功能(字节豆包 | 403点数解答 | 2025-04-06 15:37:54)294
- Python 实现球类:精准计算半径、表面积与体积,附输入验证与异常处理!(阿里通义 | 261点数解答 | 2024-11-28 21:19:39)345
- 工程师必备!10 种工程日常易用管理工具大揭秘(百度文心 | 346点数解答 | 2023-11-09 18:26:09)291
- 补全含错误代码:Vue结合Element UI组件实现查询、新增及表格展示功能 ( | 400点数解答 | 2023-12-19 15:20:50)433
- 单线程频繁查ClickHouse致CPU飙升?这些优化方案速看!(DeepSeek | 491点数解答 | 2025-02-13 17:49:54)229
- MySQL:巧用 NOT LIKE 查询字段不包含特定字符串及注意要点 (DeepSeek | 264点数解答 | 2025-02-13 18:25:01)180