これを実行してツリーを初期化しようとしています:
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);
}
しかし、セグメンテーション違反が発生しています。なぜそれが起こっているのですか?関数へのポインタを渡し、その中にメモリを確保しています。それは間違っていますか?