I want to allocate memory to a structure which is a member of another structure. I can find many examples online how to allocate memory to an array of structures or a structure pointer, but what I have now is just one structure corr as a member of structure bbb.
bbb is an array of structures within the structure aaa
Code:
struct bbb
{
int x;
int y;
struct corr ccc;
}
I have allocated memory to all bbb structures and I now want to allocate memory to:
I have tried all of the following and every time I get a compiling error:
Code:
if ((&aaa->bbb[co_b].ccc = (struct corr*) malloc(sizeof (struct corr))) == NULL) {
return EXIT_FAILURE;
}
if ((aaa->bbb[co_b].ccc = (struct corr*) malloc(sizeof (struct corr))) == NULL) {
return EXIT_FAILURE;
}
if ((aaa->bbb[co_b].ccc = (struct corr*) malloc(sizeof (struct corr*))) == NULL) {
return EXIT_FAILURE;
}
The first one gives the error lvalue required as left operand of assignment.
The last two give the error: incompatible types when assigning to type struct corr from type corr *
What would be the correct way to allocate memory to a structure in this case? Thank you!