I got a question about sizing a struct member with malloc or realloc.
Code:
stuct tst{
int iIndex;
char *szMember;
} *p_tststructs;
int iCounter = 0;
p_tststructs = malloc(sizeof(struct tst) * (iCounter +1));
// how do I size szMember here?
p_tststructs[iCounter].szMember = malloc(sizeof(char) * 10);
// or do I need to use realloc on szMember??
iCounter++;
p_tststructs = realloc(p_tststructs,sizeof(struct tst) * (iCounter+1));
// how do I size szMember here?
p_tststructs[iCounter].szMember = malloc(sizeof(char) * 10);
// or do I need to use realloc on szMember??
I left out free() and memory allocation error checks for readability. I couldn't find good tutorials about allocation of struct members so if someone got a good link then it's very welcome.
Thanks.