请用c语言输入一个图书登记管理程序
时间: 2023-04-07 08:01:40 浏览: 78
我可以回答这个问题。以下是一个简单的图书登记管理程序的C语言代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_BOOKS 100
struct Book {
char title[50];
char author[50];
int year;
};
int main() {
struct Book books[MAX_BOOKS];
int num_books = 0;
while (1) {
printf("Enter book title (or 'q' to quit): ");
char title[50];
scanf("%s", title);
if (strcmp(title, "q") == 0) {
break;
}
printf("Enter book author: ");
char author[50];
scanf("%s", author);
printf("Enter publication year: ");
int year;
scanf("%d", &year);
struct Book book;
strcpy(book.title, title);
strcpy(book.author, author);
book.year = year;
books[num_books] = book;
num_books++;
printf("Book added.\n");
}
printf("\nBook List:\n");
for (int i = 0; i < num_books; i++) {
printf("%s by %s (%d)\n", books[i].title, books[i].author, books[i].year);
}
return 0;
}
相关推荐
![text/x-c](https://img-home.csdnimg.cn/images/20210720083646.png)
![c](https://img-home.csdnimg.cn/images/20210720083646.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)