不能实现保存功能
没有ui
有待进一步开发
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
typedef struct book
{
char name[20];//图书名字
char adress[20];//图书地址
char author[20];//作者姓名
int num;//编号
int amount;//数量
struct book *next;
}BookList,*Pointer;
void Insert(Pointer *Head);
void Search(Pointer Head);
void Borrow(Pointer Head);
void Giveback(Pointer Head);
void Delete(Pointer *Head);
void Show(Pointer Head);
//void Reserve(Pointer *Head);
int main()
{
Pointer Head=NULL;
int i;
do
{
printf("\t\t\t\t\t菜单\n");
printf("1---录入\n");
printf("2---查询\n");
printf("3---借阅\n");
printf("4---归还\n");
printf("5---移除\n");
printf("6---显示\n");
printf("7---保存\n");
printf("8---退出\n");
printf("请选择功能:");
scanf("%d",&i);
switch(i)
{
case 1:Insert(&Head);break;
case 2:Search(Head);break;
case 3:Borrow(Head);break;
case 4:Giveback(Head);break;
case 5:Delete(&Head);break;
case 6:Show(Head);break;
//case 7:Reserve(&Head);break;
case 8:break;
default:printf("\n请重新输入:");break;
}
}while(i!=8);
return 0;
}
void Insert(Pointer *Head)
{
int number;
Pointer p,q,r;
printf("请输入编号:");
scanf("%d",&number);
p=q=*Head;
while(p!=NULL)
{
if(p->num==number)
{
printf("已有相同编号!");
return;
}
else
{
q=p;
p=p->next;
}
}
r=(Pointer)malloc(sizeof(BookList));
r->next=NULL;
if(r==NULL)
{
printf("error");
return;
}
if(q==NULL)
*Head=r;
else
{
q->next=r;
}
r->num=number;
printf("请输入书名 地址 作者 数量\n");
scanf("%s%s%s%d",r->name,r->adress,r->author,&r->amount);
}
void Search(Pointer Head)
{
int number;
Pointer p;
printf("请输入编号:");
scanf("%d",&number);
p=Head;
while(p!=NULL)
{
if(p->num!=number)
p=p->next;
else
{
printf("编号:%d\t书名:%s\t地址:%s\t作者:%s\t数量:%d\n",p->num,p->name,p->adress,p->author,p->amount);
break;
}
}
if(p==NULL)
printf("无此书\n");
printf("\n\n\n");
}
void Borrow(Pointer Head)
{
int number,a;
Pointer p;
printf("请输入编号:");
scanf("%d",&number);
p=Head;
while(p!=NULL)
{
if(p->num!=number)
p=p->next;
else if(p->amount!=0)
{
printf("请输入借书数量:");
scanf("%d",&a);
while(a>p->amount)
{
printf("库存不足,请重新输入:");
scanf("%d",&a);
}
p->amount=p->amount-a;
printf("成功借阅!剩余数量:%d",p->amount);
break;
}
else if(p->amount==0)
{
printf("已无剩余书籍");
break;
}
}
if(p==NULL)
printf("无此书\n");
printf("\n\n\n");
}
void Giveback(Pointer Head)
{
int number,a;
Pointer p;
printf("请输入编号:");
scanf("%d",&number);
p=Head;
while(p!=NULL)
{
if(p->num!=number)
p=p->next;
else
{
printf("请输入归还数量:");
scanf("%d",&a);
p->amount=p->amount+a;
printf("成功归还!剩余数量:%d",p->amount);
break;
}
}
if(p==NULL)
printf("无此书\n");
printf("\n\n\n");
}
void Delete(Pointer *Head)
{
int flag=1,number;
Pointer p,q;
printf("请输入编号:");
scanf("%d",&number);
p=q=*Head;
while(p!=NULL&&flag)
{
if(p->num==number)
{
if(p==*Head)
{
*Head=p->next;
free(p);
}
else
{
q->next=p->next;
free(p);
}
flag=0;
}
else
{
q=p;
p=p->next;
}
}
if(flag)
printf("无此书");
printf("\n\n\n");
}
void Show(Pointer Head)
{
Pointer p;
p=Head;
while(p!=NULL)
{
printf("编号:%d\t书名:%s\t地址:%s\t作者:%s\t数量:%d\n",p->num,p->name,p->adress,p->author,p->amount);
p=p->next;
}
printf("\n\n\n");
}
在这里插入代码片