在图书管理系统中用C语言完成图书查询的功能
时间: 2023-09-15 19:18:36 浏览: 49
当用户需要查询图书信息时,可以添加以下 C 语言函数:
```c
void searchBooks() {
char keyword[100];
int count = 0;
printf("\n====== 查询图书信息 ======\n");
printf("请输入要查询的关键词:");
scanf("%s", keyword);
for (int i = 0; i < num_books; i++) {
if (strstr(books[i].name, keyword) != NULL ||
strstr(books[i].author, keyword) != NULL ||
strstr(books[i].publisher, keyword) != NULL ||
strstr(books[i].publish_date, keyword) != NULL) {
printf("%s %s %s %s %s %f %d\n", books[i].code, books[i].name, books[i].author, books[i].publisher, books[i].publish_date, books[i].price, books[i].total);
count++;
}
}
printf("共有 %d 条符合条件的记录\n", count);
}
```
该函数首先会要求用户输入要查询的关键词,然后遍历所有图书,判断该图书的书名、作者、出版社、出版日期是否包含该关键词,如果包含,则输出该图书的信息,并统计符合条件的记录数。