生成图书管理系统的输入和输出模块c语言代码
时间: 2024-02-25 12:54:15 浏览: 19
输入模块的 C 语言代码:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct book {
char title[50];
char author[50];
int id;
};
struct book inputBook() {
struct book b;
printf("Enter book title: ");
fgets(b.title, 50, stdin);
printf("Enter book author: ");
fgets(b.author, 50, stdin);
printf("Enter book ID: ");
scanf("%d", &b.id);
getchar(); // consume newline
return b;
}
```
输出模块的 C 语言代码:
```c
void outputBook(struct book b) {
printf("Book title: %s\n", b.title);
printf("Book author: %s\n", b.author);
printf("Book ID: %d\n", b.id);
}
```
以上代码定义了一个 `book` 结构体,包含书名、作者和 ID 三个字段。函数 `inputBook` 从用户输入中读取一本书的信息并返回一个 `book` 结构体;函数 `outputBook` 输出一本书的信息。这些模块可以被图书管理系统的其他部分调用。