c - How to move memory that is already allocated to another struct -
i have following struct:
typedef struct{ char* name; int score; }student; typedef struct{ char* name; int score; }teachingassistant; i have strdup'd string name variable in student struct.
i wanted know how can move strdup'd name pointer variable teachingassistant struct don't have strdup again.
you still want use strdup when populating name in teachingassistant struct. if don't, , copy pointer, if free pointer in 1 struct other 1 becomes invalid. you'd have implement schemes keep track of pointer references otherwise.
better strdup string need it, , free each copy when don't need anymore.
Comments
Post a Comment