Need to write data to file, not sure how
Here is my code, i need to add data to the file created at the top in the struct provided, and i am not sure how to do it, any help would be greatly appreciated.
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include<conio.h>
main()
{
struct book
{
int code;
int pages;
char title[20];
char author[20];
struct book *next;
};
int pick;
FILE*library;
library=fopen("library.dat","wb");
fread(library,sizeof(struct book),1,library);
fclose(library);
printf ("\t\t\tTusket Municipal Library\n\n\n");
printf ("\tPlease make a selection...\n\n");
printf ("\t1.) Enter a book in the inventory\n");
printf ("\t2.) Delete a book from the inventory\n");
printf ("\t3.) Search the inventory for a book\n");
printf ("\t4.) Display the book inventory\n");
printf ("\t5.) Exit the program\n\n");
printf ("\tEnter your selection: \n");
scanf ("%d", &pick);
fflush(stdin);
while (pick==1)
{
struct book
{
int code;
int pages;
char title[20];
char author[20];
struct book *next;
};
int code;
int pages;
char title[20];
char author[20];
struct book *head,
*work,
*next; char answer;
work=head=(struct book*)malloc(sizeof(struct book));
do
{
printf("\nEnter Book Code: ");
scanf("%d",&code);
printf("\nEnter Book Author:");
scanf("%s",&author);
printf("\nEnter Book Title: ");
scanf("%s",&title);
printf("\nEnter Book number of Pages:");
scanf("%d",&pages);
printf("Do you wish to enter another book?:");
if(answer=='n')
{
work->next=NULL;
}
else
{
work->next=(struct book*)malloc(sizeof(struct book));
work=work->next;
}
return 0;
}