c语言图书管理系统可以运行的完整代码
时间: 2024-01-05 21:00:17 浏览: 29
由于C语言图书管理系统代码较长,不便在此处完整展示。以下是简要的C语言图书管理系统代码示例:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_BOOKS 100
struct Book {
char title[100];
char author[100];
int year;
};
struct Book library[MAX_BOOKS];
int numBooks = 0;
void addBook() {
printf("请输入书名:");
scanf("%s", library[numBooks].title);
printf("请输入作者:");
scanf("%s", library[numBooks].author);
printf("请输入出版年份:");
scanf("%d", &library[numBooks].year);
numBooks++;
printf("书籍添加成功!\n");
}
void displayBooks() {
printf("图书馆中的书籍有:\n");
for (int i = 0; i < numBooks; i++) {
printf("%d. 书名:%s, 作者:%s, 出版年份:%d\n", i+1, library[i].title, library[i].author, library[i].year);
}
}
int main() {
int choice;
while(1) {
printf("图书管理系统菜单:\n");
printf("1. 添加书籍\n");
printf("2. 显示所有书籍\n");
printf("3. 退出\n");
printf("请选择操作:");
scanf("%d", &choice);
switch(choice) {
case 1:
addBook();
break;
case 2:
displayBooks();
break;
case 3:
exit(0);
default:
printf("请输入有效选项!\n");
}
}
return 0;
}
```
上面的代码是一个简单的C语言图书管理系统,包括添加书籍和显示所有书籍的功能。真实的图书管理系统代码会更加复杂,包括更多的功能和错误处理。