I am trying to initialize a tree by doing this:
typedef struct {
char *value;
struct children_list *children;
} tree;
typedef struct t_children_list {
tree *child;
struct t_children_list *next;
} children_list;
void initializeTree(tree *root, char *input)
{
if((root = malloc(sizeof(tree))) == NULL) { abort(); }
root->value = input;
}
void main()
{
// Create the tree
char *input = "aaaaaa";
tree *my_tree = NULL;
initializeTree(my_tree, input);
}
But I am getting a segmentation fault. Why is that happening? I am passing a pointer to a function and I am reserving memory inside of it. Is that wrong?