int newbook(BOOK *lastnode,int *n){ //lastnode is the lastnode of booklist , n is the number of books
BOOK *newnode;
/* if expend the struct book , add sth here */
newnode=(BOOK *)malloc(sizeof(BOOK));
if(newnode==NULL)return 0;
*n=*n+1;
newnode->id=*n;
newnode->state=1;
newnode->next=NULL;
lastnode->next=newnode;
lastnode=newnode; //replace the lastnode;
return 1;
} //in main(),test newbook() and decide append lastnode to book.txt or not
int deletebook(BOOK *booklist,int id){
BOOK *book=booklist;
while(book){
if(book->id==id){
book->state=-1;
return 1;}
book=book->next;
}
return 0;
} /*another solution is "blacklist" ,then when you init ,just delete that node*/
int newlicense(LICENSE *lastnode , int *n){ //see newbook()
LICENSE *newnode;
newnode=(LICENSE *)malloc(sizeof(LICENSE));
if(newnode==NULL)return 0;
*n=*n+1;
newnode->id=*n;
newnode->holding=0;
newnode->next=NULL;
lastnode->next=newnode;
lastnode=newnode;
return 1;
}
int deletelicense(LICENSE *llist,int id){ //see deletebook()
/* infact we will never delete ,so there is no llist->state ....lol.... */
return 1;
}
int newborrow(BRECORD *lastnode){
int bookid,licenseid;
BRECORD *newnode;
printf("INPUT LICENSE ID & BOOK ID:")
scanf("%d %d",&licenseid,&bookid);
/*if you decide to check the record ,do it ,then you need two para:BOOK *booklist and LICENSE *list;*/
/* but in fact ,we only borrow when we realy get the book */
/* a machine do it better,so do you need a confirm? */
newnode=(BRECORD *)malloc(sizeof(BRECORD));
if(newnode==NULL)return 0;
newnode->bookid=bookid;
newnode->licenseid=licenseid;
newnode->btime=time();
newnode->next=NULL;
lastnode->next=newnode;
lastnode=newnode;
return 1;
} /* then ,test and append */
------------------------------------------------------------------
I think I need a new struct of BRECORD and RRECORD;for the easier operation on newborrow and newreturn;
BOOK *newnode;
/* if expend the struct book , add sth here */
newnode=(BOOK *)malloc(sizeof(BOOK));
if(newnode==NULL)return 0;
*n=*n+1;
newnode->id=*n;
newnode->state=1;
newnode->next=NULL;
lastnode->next=newnode;
lastnode=newnode; //replace the lastnode;
return 1;
} //in main(),test newbook() and decide append lastnode to book.txt or not
int deletebook(BOOK *booklist,int id){
BOOK *book=booklist;
while(book){
if(book->id==id){
book->state=-1;
return 1;}
book=book->next;
}
return 0;
} /*another solution is "blacklist" ,then when you init ,just delete that node*/
int newlicense(LICENSE *lastnode , int *n){ //see newbook()
LICENSE *newnode;
newnode=(LICENSE *)malloc(sizeof(LICENSE));
if(newnode==NULL)return 0;
*n=*n+1;
newnode->id=*n;
newnode->holding=0;
newnode->next=NULL;
lastnode->next=newnode;
lastnode=newnode;
return 1;
}
int deletelicense(LICENSE *llist,int id){ //see deletebook()
/* infact we will never delete ,so there is no llist->state ....lol.... */
return 1;
}
int newborrow(BRECORD *lastnode){
int bookid,licenseid;
BRECORD *newnode;
printf("INPUT LICENSE ID & BOOK ID:")
scanf("%d %d",&licenseid,&bookid);
/*if you decide to check the record ,do it ,then you need two para:BOOK *booklist and LICENSE *list;*/
/* but in fact ,we only borrow when we realy get the book */
/* a machine do it better,so do you need a confirm? */
newnode=(BRECORD *)malloc(sizeof(BRECORD));
if(newnode==NULL)return 0;
newnode->bookid=bookid;
newnode->licenseid=licenseid;
newnode->btime=time();
newnode->next=NULL;
lastnode->next=newnode;
lastnode=newnode;
return 1;
} /* then ,test and append */
------------------------------------------------------------------
I think I need a new struct of BRECORD and RRECORD;for the easier operation on newborrow and newreturn;
我是自学的,所以……