I've been tearing my hair out over this for quite a while now. What I'm trying to do is populate the struct array from within a function but I cannot figure out how to do it. Everything I've tried throws up a syntax error.
Ideally the data should be entered from the user using scanf (hence the int num within the function for a for loop), but for the sake of clarity and because this is all new material to me, I'm trying initially to fill up the struct directly from code.
I've searched all over the web for a solution, but found nothing. I've come to the conclusion that I'm approaching this entirely from the wrong angle, or there's a tiny error somewhere.
Any help would be appreciated.
typedef struct
{
char title[40];
char author[40];
int edition;
float retail_price;
} book ;
void populateStock(book stock[],int num);
void main()
{
book stock[10];
populateStock(stock,5);
}
void populateStock(book stock[],int num)
{
stock[0]={"example title1","example author1",1,5.80};
stock[1]={"example title2","example author2",4,7.20};
//And so on...//
}