I am trying to allocate a dynamic array of number elements in which each element is of a structure type. The structure is
Here is what I have so far:Code:struct person { char name[20]; int age; }; typedef struct person Person;
my main function:
Here is my allocate function so far:Code:int main( void ) { int number = 3; Person *p = allocate( number ); system("PAUSE"); return 0; }
When I try to compile this, it tells me that variable-sized object cannot be initialized. I have tried everything I could think of. I am still new to C, so it might be obvious. What am I doing wrong?Code:struct person* allocate( int number ) { Person *people[number] = ( Person* ) malloc( sizeof( Person ) * number ); }