From 80953ed0ec5cf858b29f0d3a7861cdc05d5cbff4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=B1=9F=E6=A5=A0?= <87896121@qq.com> Date: Sun, 21 May 2023 10:25:13 +0800 Subject: [PATCH] C4 --- 图书管理系统.c | 65 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/图书管理系统.c b/图书管理系统.c index d7ca4af..01c428f 100644 --- a/图书管理系统.c +++ b/图书管理系统.c @@ -109,7 +109,70 @@ void ShowLibBook(Book* book1) } //C4 - +Book* AddBook(Book* book1) +{ + Book* book = book1; + if (book == NULL) + { + Book* tmp = (Book*)malloc(sizeof(Book)); + tmp->next = NULL; + assert(tmp); + printf("输入书的编号:"); + scanf("%d", &tmp->iNum); + getchar(); + printf("输入书的名称:"); + gets(&tmp->acName); + printf("输入书的作者:"); + gets(tmp->acAuthor); + printf("输入书的出版社:"); + gets(tmp->acPress); + printf("输入书的库存量:"); + scanf("%d", &tmp->iAmount); + book = tmp; + printf("按任意键返回\n"); + getchar(); + return book; + return; + } + while (1) + { + while (book->next == NULL) + { + int flag = 1; + while (flag) + { + Book* tmp = (Book*)malloc(sizeof(Book)); + tmp->next = NULL; + assert(tmp); + printf("输入书的编号:"); + scanf("%d", &tmp->iNum); + getchar(); + printf("输入书的名称:"); + gets(&tmp->acName); + printf("输入书的作者:"); + gets(tmp->acAuthor); + printf("输入书的出版社:"); + gets(tmp->acPress); + printf("输入书的库存量:"); + scanf("%d", &tmp->iAmount); + book->next = tmp; + printf("是否继续输入:1==>继续\t0==>结束\t"); + scanf("%d", &flag); + getchar(); + if (flag == 0) + { + printf("按任意键返回\n"); + getchar(); + return book1; + } + } + } + book = book->next; + } + printf("按任意键返回\n"); + getchar(); + return; +} //C5 //C6