我的结构如下:
struct dir{
char *path;
int count;
struct dir **subdir
};
struct dir *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 with strcpy as well
node->count = count_to_copy;
node->subdir = malloc(count_to_copy * sizeof(*dir));
当我打印node-> name时,无论我尝试什么,它总是打印0x0。我做错了什么?