My code is in Croatian...
I type full book name with spaces in bookname,name and surname of author in author,and year in year with this:
Code:
printf("\nHow many books do you want to type in?\n");
scanf("%d",&n);
for(i=0;i<n;i++){
fseek(f,0,SEEK_END);
printf("\nWrite in the name of %d. book:\n",i+1);
scanf(" %[^\n]",k[i].bookname);
printf("\nWrite in the name of %d. author:\n",i+1);
scanf(" %[^\n]",k[i].author);
printf("\nWrite the year of %d. book:\n",i+1);
scanf("%d",&k[i].year);
fprintf(f,"%s %s %d\n",k[i].bookname,k[i].author,k[i].year);}
and when i open file it look like this:
King John William Shakespeare 1590
Rome and Juliett William Shakespeare 1600
but when i want to printf all books from file with this code:
Code:
for(i=0;i<counter;i++){
fscanf(f,"%s %s %d",k[i].bookname,k[i].author,&k[i].year);
printf("\n%d\t%s\t%s\t%d",(i+1),k[i].bookname,k[i].author,k[i].year);}
I get output like this
Number Book name Author name Year
1 King John 0
2 William Shakespeare 1590