用c语言写一个图书馆管理系统
时间: 2023-09-13 13:05:08 浏览: 38
好的,下面是一个简单的图书馆管理系统,包括添加图书、借出图书、归还图书和查询图书等功能,代码如下:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_BOOKS 100
// 图书结构体
struct book {
char title[50];
char author[20];
int id;
int borrowed; // 是否借出:1表示借出,0表示未借出
};
// 图书馆结构体
struct library {
struct book books[MAX_BOOKS];
int count; // 当前图书数量
};
// 初始化图书馆
void init_library(struct library *lib) {
lib->count = 0;
}
// 添加图书
void add_book(struct library *lib, char *title, char *author, int id) {
// 判断图书是否已经存在
for (int i = 0; i < lib->count; ++i) {
if (lib->books[i].id == id) {
printf("该图书已存在!\n");
return;
}
}
// 添加新图书
struct book new_book;