I have a structure filed that I have created and am trying to get it to display in my main function. I keep getting the the error:
" error: initializer element is not constant
struct childrensBooks *book1 = (struct childrensBooks *) malloc(sizeof(struct childrensBooks)); //Structure of book #1
^
lab2Structure.h:11:1: error: expected identifier or ‘(’ before ‘{’ token {
How can i fix this?? Here is my structure.h file:
struct childrensBooks
{
char *title; //use of pointers to store memory for title
char *author; //use of pointers to store memory for author
char *publisher; //use of pointers to store memory for publisher
int copyright;
double price;
};
struct childrensBooks *book1 = (struct childrensBooks *) malloc(sizeof(struct childrensBooks)); //Structure of book #1
{
book1->title = (char *)malloc(100);
book1->author = (char *)malloc(100);
book1->publisher = (char *)malloc(100);
book1->copyright = 1997;
book1->price = 8.99
memcpy(book1->title, "We're Going on a Bear Hunt", 26);
memcpy(book1->author, "Michael Rosen", 13);
memcpy(book1->publisher, "Little Simon", 12);
book1->copyright = 1989;
book1->price = 7.99;
fprintf(stderr, "%s was written by %s\n. Publisher is %s. Copyright %d\n. Retail price is $%.2d\n.", book1->title, book1->author, book1->publisher,
book1->copyright, book1->price);
}