/*  File: main5s.C

    Main program that uses the list ADT to for
    linked list of structs
*/

#include <stdio.h>
#include <stdlib.h>
#include "structitem.h"
#include "list5.h"

main(int argc, char *argv[]) {

FILE *ifile ;
book_t onebook ;
int count, r ;
List *Books ;

   if (argc < 2) {
      fprintf(stderr, "Usage: a.out filename\n") ;
      exit(1) ;
   }

   Books = new List ;

   printf("Loading %s\n", argv[1]) ;

   ifile = fopen(argv[1], "rb") ;
   if (ifile == NULL) {
      fprintf(stderr, "couldn't open file\n" ) ;
      exit(1) ;
   }

   while(1) {
      r = fread(&onebook, sizeof(book_t), 1, ifile) ;
      if (r == 0) break ;

      count++ ;
/*
      printf("%02d. %s, $%.2f\n", count, onebook.title, onebook.price) ;
*/
      Books->Append(&onebook) ;
   } 

   fclose(ifile) ;

   Books->Print() ;
}
