I just can't understasnd how fwrite finction works in c.I had made a c program.here it it:-
#include <stdio.h>
int main()
{
struct books
{
char name[100];
float price;
int pages;
}book1;
puts("enter the name of the book");gets(book1.name);
puts("enter the price of the book");scanf("%f",&book1.price);
puts("enter the pages of the book");scanf("%d",&book1.pages);
FILE *b=fopen("Book.txt","w");
fwrite(&book1,sizeof(book1),1,b);
}
here is input of th program:-
$ ./a.out
enter the name of the book
Voldemort the last BSD user
enter the price of the book
40000
enter the pages of the book
34
and here is the content of the file:-
$ cat Book.txt
Voldemort the Great Linux and bsd user!����c����@�@��,B
Thus what is wrong in my program ? How does fwrite works ? When should I use it?