From 7e8d742ebe8ec1487b6abdcc9a2362911a909095 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:26:40 +0800 Subject: [PATCH] C5 --- 图书管理系统.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/图书管理系统.c b/图书管理系统.c index 01c428f..514604e 100644 --- a/图书管理系统.c +++ b/图书管理系统.c @@ -174,7 +174,39 @@ Book* AddBook(Book* book1) return; } //C5 - +Book* DealoldBook(Book* book1) +{ + Book* book = book1; + Book* prev = book1; + printf("输入要处理旧书的编号:"); + int id; + scanf("%d", &id); + getchar(); + while (book != NULL) + { + if (id == book->iNum) + { + if (book1 == book) + { + book = book->next; + free(prev); + return book; + } + prev->next = book->next; + free(book); // free():释放资源 + printf("已将旧书处理掉!\n"); + printf("按任意键返回\n"); + getchar(); + return book1; + } + prev = book; + book = book->next; + } + printf("没有找到该图书\n"); + printf("按任意键返回\n"); + getchar(); + return book1; +} //C6 //C7