I'm trying to understand if my code is correct. I need to declare an array of pointers to structs, create a new struct and assign the values and print them. It seems to me that I'm not declaring array of pointers correctly. I need to know what I'm doing wrong. Thank you I'm getting this compile error: error: 'people' undeclared (first use in this function) And I've tried to insert struct data *list; into main but it wouldnt work
char *book[] = { "x", "y", "z",};
int number[] = { 1, 2, 3};
struct data = { char *bookname; int booknumber;};
function(char *x, int y)
{
static int count;
struct data *list[3];
//creating a new struct
list[count] = (struct data*) malloc( sizeof(struct data) );
//assigning arguments
list->bookname = x;
list->booknumber = y;
count++;
}
int main()
{
struct data *list[3];
int i;
for(i = 0; i < 3; i++)
{
function(book[i], number[i]);
printf("name: %c number: %d", list[i]->bookname, list[i]->booknumber);
}