Как указали другие, во-первых, children
имеет тип node_t **
, и вы выделили память только для root->children
, а не для root->children[row]
.Выделите память динамически для root->children[row]
и назначьте некоторые значения.Это может выглядеть так:
root->arr_len = INIT_SIZE;
for(int row = 0; row < root->arr_len ;row++) {
root->children[row] = malloc(sizeof(node_t));/* allocate memory for each children */
root->children[row]->arr_len = row + 99;/* ?? assign some values into member of struct so that you can print in
set_array_vals & verify */
}
И в set_array_vals()
начинайте печать с i=0
, как указано выше, вы выделяете память от root->children[0]
до root->children[9]
, а доступ за пределы размера может привести к неопределенному поведению.
void set_array_vals(node_t *root) {
for (int i = 0; i < root->arr_len; i++) { /* start printing from i=0 , not i=1 */
#if 0
node_t *this_node = root->children[i]; /* no need of any temporary pointer */
printf("%d: %d\n", i, this_node->arr_len);
#endif
printf("%d: %d\n", i, root->children[i]->arr_len);
}
}