图书管理系统(C语言)

这是图书管理系统的源代码,大一的课程设计,只供参考哦
#include
#include
#include
#include

struct book
{
	char name[20];
	char year[10];
	char zz[20];
	int cs;
	int jg;
	struct book *next;
};

struct book * lianbiao()		//产生头结点
{
	struct book *head;
	head=(struct book *)malloc(sizeof(struct book));
	head->next=NULL;
	return head;
}

int tianjia(struct book *head,int b)		//添加一本新书
{
	struct book *ptemp=head,*pnew;
	pnew=(struct book *)malloc(sizeof(struct book));
	fflush(stdin);
	printf("请输入书籍名称:");
	gets(pnew->name);
	printf("请输入出版日期:");
	gets(pnew->year);
	printf("请输入书籍作者:");
	gets(pnew->zz);
	printf("请输入书籍册数:");
	scanf("%d",&pnew->cs);
	printf("请输入书籍价格:");
	scanf("%d",&pnew->jg);
	fflush(stdin);
	pnew->next=NULL;
	while(ptemp->next!=NULL)
	{
		ptemp=ptemp->next;
	}
	ptemp->next=pnew;
	b++;
	return b;
}

int huifu(struct book *head)			//将文件中数据恢复至内存
{
	FILE * fp;
	int i=0,j=0;
	struct book *ptemp=head,*pnew;
	fp=fopen("a.mr","rt");
	while(1)
	{
		pnew=(struct book *)malloc(sizeof(struct book));
		i=fscanf(fp," %s %s %s %d %d",pnew->name,pnew->year,pnew->zz,&pnew->cs,&pnew->jg);
		if(i==EOF)break;
		pnew->next=NULL;
		ptemp->next=pnew;
		ptemp=ptemp->next;
		j++;
	}
	free(pnew);
	fclose(fp);
	return j;
}

void tuichu(struct book * head)		//将内存数据保存至文件
{
	FILE * fp;
	struct book * ptemp=head;
	fp=fopen("a.mr","w");
	while(ptemp->next!=NULL)
	{
		ptemp=ptemp->next;
		fprintf(fp," %s %s %s %d %d",ptemp->name,ptemp->year,ptemp->zz,ptemp->cs,ptemp->jg);
	}
	fclose(fp);
}

void fshuming(struct book *head)		//按书名查找
{
	struct book *ptemp=head;
	char a[20];
	int b=1;
	printf("请输入书籍名称:");
	gets(a);
	printf("-------------------------------------------------------------\n");
	printf("序号 |书名      |出版时间  |作者      |剩余册数 
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值