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

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -