I'm having trouble finding the answer to this problem; I've found similar examples of this online but none that address my problem.
I have a struct for the data for a company, Company, and a second struct for collections of companies, Consortium. The second struct will contain variable length arrays of the first struct, the company data struct. The number of elements of the variable length arrays will depend on the number of companies in a consortium.
I want to dynamically allocate whatever is required but I'm getting a bit lost. These are the structs:
typedef struct {
char code[];
double sharePrice;
int numShares;
double totalVal;
double totalDebts;
} Company;
typedef struct {
int numCore;
int numAssoc;
Company core[];
Company assoc[];
} Consortium;
There will be a number of core companies, and this number will be the size of the core array in the Consortium struct. Same goes for associate companies.
I came up with this expression but I'm not sure what I'm missing:
Consortium *consort=((Consortium*)malloc((numCore+numAssoc)*(sizeof(Consortium));