c - Malloc string inside struct -


my structure looks this:

struct dir{     char *path;     int count;     struct dir **subdir }; struct dir *node; 

i doing following allocate memory node:

name_to_copy = "root" count_to_copy = 5; node = malloc(sizeof(*node)); node->path = malloc(strlen(name_to_copy)+1); memcpy(node->path, name_to_copy, strlen(name_to_copy)+1); //tried strcpy node->count = count_to_copy; node->subdir = malloc(count_to_copy * sizeof(*dir)); 

when print node->name, no matter try, prints 0x0. doing wrong?


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

post - imageshack API cURL -