学校周边医院信息管理程序功能:实现学院周边医院信息的管理,如新生成、添加、删除、浏览、修改等功能,最好用文件系统存储数据信息,有没有人帮帮我,麻了
找个类似的修改一下即可
#include <stdio.h>
#include <stdlib.h>
struct hospital {
char name[50];
char address[100];
char phone[20];
};
void add_hospital() {
struct hospital h;
printf("Enter hospital name: ");
scanf("%s", h.name);
printf("Enter hospital address: ");
scanf("%s", h.address);
printf("Enter hospital phone: ");
scanf("%s", h.phone);
FILE *fp = fopen("hospitals.dat", "ab");
fwrite(&h, sizeof(struct hospital), 1, fp);
fclose(fp);
printf("Hospital added successfully.\n");
}
void view_hospitals() {
struct hospital h;
FILE *fp = fopen("hospitals.dat", "rb");
while (fread(&h, sizeof(struct hospital), 1, fp) == 1) {
printf("Name: %s\nAddress: %s\nPhone: %s\n\n", h.name, h.address, h.phone);
}
fclose(fp);
}
int main() {
int choice;
while (1) {
printf("1. Add hospital\n2. View hospitals\n3. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
add_hospital();
break;
case 2:
view_hospitals();
break;
case 3:
exit(0);
default:
printf("Invalid choice.\n");
}
}
return 0;
}
参考:http://www.zzvips.com/article/175800.html
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!