i am trying to write a database for my books
burt when i want to read from a file into my linked list
it breaks everything up in words
the file looks like this
stevens
network programming
second
1-123-456
maddison
good
stevens
tcp/ip illustrated
second
0-123-456
maddison
good
i use fscanf
i tried to replace it with fread and fgets but no succes
here is the code of my print fuctions
there are more functions i think these are the onesCode:struct dbline{ char author[BUFSIZE]; char title[BUFSIZE]; char edition[BUFSIZE]; char isbn[10]; char publisher[BUFSIZE]; char comment[BUFSIZE]; struct dbline *next_rec; }; typedef struct dbline LIST; typedef LIST *LINK; FILE *open_file_to_read(FILE *fp ,char *filename) { if((fp = fopen(filename ,"r")) == NULL) { fprintf(stderr ,"error opening file"); exit(-1); } return fp; } LINK read_to_list(FILE *fpr, LINK first) { LIST tmp_rec ; LINK new_rec = NULL; LINK cur_rec = NULL; while(fscanf(fpr, "%s\n%s\n%s\n%s\n%s\n%s\n", tmp_rec.author, tmp_rec.title, tmp_rec.edition, tmp_rec.isbn ,tmp_rec.publisher, tmp_rec.comment)!= EOF) { new_rec = (LINK) malloc(sizeof(LIST)); *new_rec = tmp_rec; if (cur_rec == NULL) { cur_rec = new_rec; first = new_rec; } else { cur_rec->next_rec = new_rec; cur_rec=new_rec; } new_rec->next_rec = NULL; } return first; } void print_all(LINK first) { LINK cur_rec = NULL; cur_rec = first; while (cur_rec != NULL) { printf("\nauthor: %s", cur_rec->author); printf("\ntitle: %s", cur_rec->title); printf("\nedition: %s", cur_rec->edition); printf("\nisbn: %s", cur_rec->isbn); printf("\npublisher: %s", cur_rec->publisher); printf("\ncomment: %s", cur_rec->comment); cur_rec = cur_rec->next_rec; }
messing things up
can anybody tell me what i am doing wrong



LinkBack URL
About LinkBacks


