Let\'s say you have-
struct Person {
char *name;
int age;
int height;
int weight;
};
If you do-
struct Pe
For pointers the struct is allocated enough memory just for the pointer. You have to create the memory for the char* and assign the value to the struct. Assuming you had char* name
somewhere:
struct Person *who = malloc(sizeof(struct Person));
who->name = malloc((strlen(name)+1) * sizeof(char));
strcpy(who->name, name)