#include"stdlib.h"
#include"string.h"
typedef struct bookinfo
{
  char ID[10];
  char name[20];
  char author[20];
  char publisher[20];
  char publishtime[20];
  char ISBN[20];
  int  banci;
  int  price;
  int  onshelf;
  char readername[20];
  char borrowtime[20];
  struct bookinfo*next;
}bookinfo;
typedef struct book
{
  int bookid;
  bookinfo*h;
  struct book*next;
}book;
typedef struct readerinfo
{
  char ID[20];
  char name[20];
  char leibie[3];
  bookinfo*h;
  int borrownum;
  readerinfo*next;
}readerinfo;
typedef struct reader
{
  char danwei[20];
  readerinfo*h;
  struct reader*next;
}reader;
book*init_book()
{
  book*l;
  bookinfo*h;
  l=(book*)malloc(sizeof(book));
  if(l==NULL)
  {
   exit(0);
  }
  h=(bookinfo*)malloc(sizeof(bookinfo));
  h->next=NULL;
  l->h=h;
  l->next=NULL;
  return l;
}
int insertbook(book**l,int bookid)
{
  book*p=*l;
  p=(book*)malloc(sizeof(book));
  if(p==NULL)
  {
    exit(0);
  }
  p->bookid=bookid;
  p->next=NULL;
  (*l)->next=p;
  (*l)=(*l)->next;
  return 1;
}
int intsertbookinfo(bookinfo**pi,char*ID,char*name,char*author,char*publisher,char*publishtime,char*ISBN, int banci,int price)
{
 bookinfo*p;
 p=(bookinfo*)malloc(sizeof(bookinfo));
 if(p==NULL)
 {
    exit(0);
 }
 p->next=NULL;
 strcpy(p->ID,ID);
 strcpy(p->name,name);
 strcpy(p->author,author);
 strcpy(p->publisher,publisher);
 strcpy(p->publishtime,publishtime);
 strcpy(p->ISBN,ISBN);
 p->banci=banci;
 p->price=price;
 p->onshelf=0;
 (*pi)->next=p;
 (*pi)=(*pi)->next;
 return 1;
}int create_book(book**l)
{
 book*p=*l;
 int id;
 FILE*fp;
 fp=fopen("book.txt","r+");
 fscanf(fp,"%d",&id);
 while(id!=0)
 {
  insertbook(&p,id);
  fscanf(fp,"%d",&id);
 }
}int create_bookinfo(book**l)
{
   book*p1=(*l)->next;
   char*flag="end";
   bookinfo*p,*q;
   char ID[10];
   char name[20];
   char author[20];
   char publisher[20];
   char publishtime[20];
   char ISBN[20];
   int  banci;
   int  price;
   FILE*fp;
   fp=fopen("bookinfo.txt","r+");
   if(fp==NULL)
   {
     printf("can not found the file");
     exit(0);
   }
   int bookid;
   fscanf(fp,"%d",&bookid);
   while(bookid!=0)
   {    for(;p1!=NULL;p1=p1->next)
     {
       if(p1->bookid==bookid)
 {    break;
 }     }
     fscanf(fp,"%s",ID);
       while(strcmp(ID,flag)!=0)
       {  fscanf(fp,"%s%s%s%s%s%d%d",name,author,publisher,publishtime,ISBN,&banci,&price);
 intsertbookinfo(&(p1->h),ID,name,author,publisher,publishtime,ISBN,banci,price);
 fscanf(fp,"%s",ID);
       }
       fscanf(fp,"%d",&bookid);
     }
}void display(book*l)
{  book*p;
  bookinfo*h;
  p=l->next;
  if(p==NULL)
  printf("0");
  for(;p!=NULL;p=p->next)
   {
   printf("%d",p->bookid);
   bookinfo*h;
   h=p->h->next;
   while(h!=NULL)
   {
     printf("%s",h->ID);
     h=h->next;
   }
  }
}
void main()
{
 clrscr();
 book*bl;
 bl=init_book();
 create_book(&bl);
 create_bookinfo(&bl);
 display(bl);
 getch();}