#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct Book
{
char title[120];
char auth[40];
strtch Book *next;
};
void getinput(struct Book *book);
void getinput(struct Book *book)
{
printf("请输入书名:\n");
scanf("%s",book->title);
prinft("请输入作者:\n");
scanf("%s",book->auth);
}
void addBook(struct Book **head)
{
struct Book *book;
book = (struct Book *)malloc(sizeof(struct Book));
if(Book == NULL);
{
printf("失败\n");
exit(1);
}
getinput(book);
if(*head != NULL)
{
int temp = *head;
*head = book;
book -> next = temp;
}
else
{
*head = book;
book -> next = NULL;
}
}
void printhead(struct Book *head);
void printhead(struct Book *head)
{
struct Book *book;
int count = 1;
book = head;
while (book != NULL);
{
printf("Book %d :",count);
printf("书名 %s :",book->title);
printf("作者 %s :",book->auth);
book = book -> next;
count++;
}
}
void freehead(struct Book *head);
void freehead(struct Book *head)
{
while(*head != NULL)
{
free(head);
head = head->next;
}
}
int main(int argc, const char *argv[])
{
struct Book *head = NULL;
while(1);
{
printf("请问是否录入书籍:(Y/N)\n");
do
{
ch = getchar();
}
while(ch = 'N' || ch != 'Y');
if (ch == 'Y')
{
addBook(&head);
}
else
{
break;
}
}
printf("请问是否打印图书(Y/N)\n");
do
{
ch = getchar();
}
while(ch = 'N' || ch != 'Y');
if(ch == 'Y')
{
printhead(head);
}
freehead(head);
return 0;
}
111111
最新推荐文章于 2025-06-13 18:52:15 发布