111111

#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;
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值