【C語言】《帶你學(xué)C帶你飛》

自己寫的圖書館代碼(請各位多多指教批評)
#include <stdio.h>
//聲明函數(shù)
extern int setlibrary(void);
extern void library(int num);
extern struct Book* setbook(int booknum, struct Book* book);
extern void seeallbook(int);
//書日期的結(jié)構(gòu)體
struct Time
{
int year;
int month;
int day;
};
//書的信息結(jié)構(gòu)體
struct Book
{
char name[128];
struct Time time;
int numwords;
};
struct Book book[10000];
//獲取將要輸入的書籍?dāng)?shù)量函數(shù)
int setlibrary (void)
{
int booksnum;
printf("請輸入存儲書籍?dāng)?shù)量:");
scanf("%d",&booksnum);
//getchar();
return booksnum;
}
//設(shè)置書籍信息
struct Book* setbook(int booknum,struct Book* book)
{
printf("請輸入第%d本書的書名:", booknum +1);
scanf("%s",&book->name);
printf("請輸入第%d本書的日期:", booknum +1);
scanf("%d/%d/%d", &book->time.year, &book->time.month, &book->time.day);
printf("請輸入第%d本書的字?jǐn)?shù):", booknum + 1);
scanf("%d", &book->numwords);
putchar(getchar());
return book;
}
//看所有書籍
void seeallbook(int booksnum)
{
for (int i = 0; i < booksnum; i++)
{
printf("您輸入的第%d本書名是:%s\n", i + 1, book[i].name);
printf("您輸入的第%d本書日期是:%d/%d/%d\n", i + 1, book[i].time.year, book[i].time.month, book[i].time.day);
printf("您輸入的第%d本書字?jǐn)?shù)是:%d\n", i + 1, book[i].numwords);
printf("\n");
}
}
//圖書館函數(shù)
void library(int num)
{
for (int i = 0 ; i < num; i++)
{
setbook(i,&book[i]);
}
}
//主函數(shù)
int main(void)
{
int booksnum = setlibrary();
library(booksnum);
printf("是否查看所有書籍(Y/N):");
char see = getchar();
if (see == 'Y' || see == 'y')
{
printf("\n");
seeallbook(booksnum);
printf("一共錄入%d本書,顯示成功!", booksnum);
}
return 0;
}
==================================運(yùn)行結(jié)果:
請輸入存儲書籍?dāng)?shù)量:3
請輸入第1本書的書名:《你好世界!》
請輸入第1本書的日期:2023/1/28
請輸入第1本書的字?jǐn)?shù):6666
請輸入第2本書的書名:《你好編程!》
請輸入第2本書的日期:2023/1/28
請輸入第2本書的字?jǐn)?shù):8888
請輸入第3本書的書名:《你好c語言!》
請輸入第3本書的日期:2023/1/28
請輸入第3本書的字?jǐn)?shù):9999
是否查看所有書籍(Y/N):Y
您輸入的第1本書名是:《你好世界!》
您輸入的第1本書日期是:2023/1/28
您輸入的第1本書字?jǐn)?shù)是:6666
您輸入的第2本書名是:《你好編程!》
您輸入的第2本書日期是:2023/1/28
您輸入的第2本書字?jǐn)?shù)是:8888
您輸入的第3本書名是:《你好c語言!》
您輸入的第3本書日期是:2023/1/28
您輸入的第3本書字?jǐn)?shù)是:9999
一共錄入3本書,顯示成功!