Post date: Jan 21, 2014 2:09:29 AM
#include <stdio.h>
int main()
{ FILE* booksfile = fopen("books.txt","w");
if(booksfile == 0)
printf("File cannot be opened.\n\n");
int codebook,year,price;
char booktitle[80], author[80];
printf("Enter a number for each book. (0 for quit):");
for(;;)
{
printf("\n\nBook Code: ");
scanf("%d",&codebook);
if(codebook == 0)
break;
fprintf(booksfile,"%d ", codebook);
fflush(booksfile);
printf("\ntitle: ");
scanf("%s",booktitle);
fprintf(booksfile,"%s ", booktitle);
fflush(booksfile);
printf("\nAuthor: ");
scanf("%s",author);
fprintf(booksfile,"%s ", author);
fflush(booksfile);
printf("\nYear: ");
scanf("%d",&year);
fprintf(booksfile,"%d ", year);
fflush(booksfile);
printf("\nPrice: ");
scanf("%d",&price);
fprintf(booksfile,"%d \n", price);
fflush(booksfile);
}
return 0;
}