# include & ltstdlib.h & gt
# include & ltstring.h & gt
# Define Borrowing 1
# Define NOBORROW 0
/* Define the book structure */
Structural book
{
Int _ id// number, unique
char _ name[32]; //The name of the book is not unique.
char _ author[32]; //The author of the book is not unique.
The type of int _ type// book is not unique.
Int _ status// The status of the book, whether to borrow it or not.
Int _ count// Number of times books are lent out
Struct Book * _ next// Next book
Structure book * _ prev// The last book
};
/* Define reader structure */
//structure reader
//{
//int _ rid;
//char _ rname[32];
/* Directory prompt for operation */
char book_menu[][32] =
{
"Book management",
"Reader management",
"Book lending management",
"Return management",
"Query and statistics",
"Exit the system",
"stack",
"",
};
/* Directory prompt for operation 1
char book_menu_sub[][32] =
{
"Book query",
"Readers' questions",
"",
};
/* Add book type (publishing house) and display user information */
char book_types[][32] =
{
"Publisher 1",
"Publisher 2",
"publisher 3",
"",
};
/* Add the book status, and the user information will be displayed */
char book_status[][32] =
{
"no fasting",
"lease",
"",
};
/* Add books, and the id will be numbered automatically */
int add_books(Book* head,Book* book_for_add)
{
Book * p = head;
If (! p)
return- 1;
while(p->; _ Next)
{
p = p-& gt; _ next
};
p->; _ next = book _ for _ add
book _ for _ add-& gt; _ id = p-& gt; _ id+ 1;
book _ for _ add-& gt; _ prev = p;
book _ for _ add-& gt; _ next = NULL
book _ for _ add-& gt; _ count = 0;
book _ for _ add-& gt; _ status = 0;
Returns 0;
};
/* Add readers, and the id will be numbered automatically */
//int add_readers(Reader* head,Reader* reader_for_add)
//{
//Reader * p = rhead;
//If (! p)
//return- 1;
//while(p-& gt; _rnext)
// {
//p = p-& gt; _ rnext
// };
//p-& gt; _ rnext = reader _ for _ add
//reader _ for _ add-& gt; _ rid = p-& gt; _ id+ 1;
//reader _ for _ add-& gt; _ rprev = p;
//reader _ for _ add-& gt; _ rnext = NULL
//Returns 0;
//};
/* Establish a linked list of book management */
Book * Create _ List (Book * Book _ Header)
{
if (book_head)
{
book _ head-& gt; _ prev = book _ head
book _ head-& gt; _ next = NULL
book _ head-& gt; _ id = 1;
book _ head-& gt; _ count = 0;
book _ head-& gt; _ status = 0;
}
Return the book _ head;
}
/* Release linked list */
Void free list (Book* book_head)
{
Book *p, * p1;
p = book _ head
while(p)
{
p 1 = p->; _ next
Free (p);
p = p 1;
}
}
/* Print book information */
void print_book(Book* book)
{
Printf ("ISBN: %d, title: %s, author: %s, publisher: %s, status: %s, borrowing times: %d\n ",
Book-> _id,book-& gt; _name,book-& gt; _ Author, Book Type [Book-> _type],
book _ status[book-& gt; _status],book-& gt; _ count);
}
/* List all registered books */
Invalid list _ book (Book* book_head)
{
Book * p = book _ header;
while (p)
{
print _ book(p);
p = p-& gt; _ next
}
}
/* Borrow a book and return a pointer to the book, otherwise return NULL. There may be no books, or they have been borrowed */
Book * borrow _ books(Book * Book _ head,int id)
{
Book * p = book _ header;
while (p)
{
If (p->; _id == id)
Break;
p = p-& gt; _ next
}
If (! P)/* does not exist */
Returns NULL
If (p->; _ status! = 0) /* has been borrowed */
Returns NULL
p->; _ status = 1; /* Book Lending Registration */
p->; _ count++; /* Borrowing Times+1 */
Return p;
}
/* Find the book title and return the book number found. The title of the book can be repeated, and there can be more than one book, but the ID is unique */
int search _ books _ by _ name(Book * Book _ head,char* name)
{
int count = 0;
Book * p = book _ header;
while (p)
{
if(strcmp(p-& gt; _name,name) == 0)
{
print _ book(p);
++counting;
}
p = p-& gt; _ next
}
Returns the count;
}
/* Find the book type and return the number found. There will be many books in one genre */
int search _ books _ by _ type(Book * Book _ head,int type)
{
int count = 0;
Book * p = book _ header;
while (p)
{
If (p->; _type == type)
{
print _ book(p);
++counting;
}
p = p-& gt; _ next
}
Returns the count;
}
//int search _ books _ by _ id(Book * Book _ head,char* id)
//{
//int count = 0;
//Book * p = Book _ head;
// while (p)
// {
//if(strcmp(p-& gt; _id,id) == 0)
// {
//print _ book(p);
//++count;
// }
//p = p-& gt; _ next
// }
//
//Returns the count;
//}
/* Return the book. If it returns normally, it returns the pointer to the book, otherwise it returns NULL */
Book * return _ books(Book * Book _ head,int id)
{
Book * p = book _ header;
while (p)
{
If (p->; _ id = = id & amp& ampp->; _ status! = 0)
{
p->; _ status = 0; /* Book Return Registration */
Break;
}
p = p-& gt; _ next
}
Return p;
}
/* Print operation options */
void print_menu(char menus[][32])
{
int no = 0;
Printf ("\ nBook lending management system \ n");
while (strlen(menus[no]))
{
printf("%d.%s\n ",no+ 1,menus[no]);
++No;
}
Printf ("menu option (");
While (no)
{
printf("/%d ",no-);
}
printf("):);
}
/* Main function */
int main(void)
{
char key = 0;
char ss[ 128];
int loop = 1;
Book first_book、*pBooks、* pTmp
strcpy(first_book。 _name, "Library Guide");
strcpy(first_book。 _author,“admin”);
The first book. _ type = 0;
pBooks = create _ list(& amp; first _ book);
While (loop)
{
print _ menu(book _ menu);
gets(ss);
key = ss[0]-48;
if(key & lt; 1 | | key & gt; 7)
Printf ("Input error, please re-enter! \ n ");
other
Printf ("option entered: %d\n", key);
Switch (key)
{
Case 1: // Add Books
pTmp =(Book *)malloc(sizeof(Book));
Intermediate frequency (pTmp)
{
Printf ("add title:");
gets(ss);
strncpy(pTmp-& gt; _name,ss,3 1);
Printf ("add author:");
gets(ss);
strncpy(pTmp-& gt; _ Author, ss, 31);
print _ menu(book _ types);
gets(ss);
key = ss[0]-48;
if(key & lt; = 0 | | key & gt(sizeof(book _ type)/32))
key = 1;
pTmp-& gt; _ type = key- 1;
add_books(pBooks,pTmp);
}
Break;
Case 2: // Add Readers
Case 3://Borrowing books
Printf ("Enter the borrowed ISBN:");
gets(ss);
key = atoi(ss);
pTmp = borrow_books(pBooks,key);
If (! pTmp)
Printf ("Borrowing failed, ISBN: %d\n", key);
other
{
Printf ("The loan is successful! \ n ");
print _ book(pTmp);
}
Break;
Case 4: // Returning Books
Printf ("Enter ISBN to be returned:");
gets(ss);
key = atoi(ss);
pTmp = return_books(pBooks,key);
If (! pTmp)
Printf ("return failed, ISBN: %d\n", key);
other
{
Printf ("Return succeeded! \ n ");
print _ book(pTmp);
}
Break;
Case 5: // Searching for Books
print _ menu(book _ menu _ sub);
gets(ss);
key = ss[0]-48;
Printf ("option entered: %d\n", key);
Switch (key)
{
Case 1: // Searching for Books by Name
Printf ("Enter title:");
gets(ss);
key = search _ books _ by _ name(pBooks,ss);
if(key == 0)
Printf ("No books! \ n ");
Case 2: // Searching for Books by Type
print _ menu(book _ types);
gets(ss);
key = ss[0]-48;
key = search _ books _ by _ type(pBooks,key);
if(key == 0)
Printf ("There is no such publishing house! \ n ");
Case 3: // Searching for Books by id
Printf ("Enter ISBN:");
gets(ss);
//key = search _ books _ by _ id(pBooks,ss);
if(key == 0)
Printf ("No books! \ n ");
Default value:
Break;
}
Break;
Case 6: // Quit
loop = 0;
Break;
Default value:
Break;
Case 7: // List books
list _ books(pBooks);
Break;
}
Printf("-Enter to continue-");
gets(ss);
}
free _ list(pBooks);
Returns 0;
}
I haven't tried the previous program, so you can change it yourself.