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

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -