My question is similar to this. Imagine this structure :
typedef struct {
char *chromosome,*sequence;
int start,end;
} localisation_t;
I want to allocate memory for an array (5 elements) of this structure. I will try something like : ( the syntax is certainly wrong, as you can assumed i'm not fluent in C ).
localisation_t *locs = (localisation_t*) calloc(5, sizeof(localisation_t));
strArray[0] = (localisation_t* ) malloc(sizeof(localisation_t));
I have often seen that a struct member can allocate memory too. I don't understand what for because you already allocate memory for the struct ?! But ok you don't know what it will contains. (here an example with strdup on the name variable member). Is it a good practice to allocate memory for member of struct (mostly when it's char * type) ?
What will happen if I don't do this ? Is it a good practice ?