【发布时间】:2013-02-23 15:51:48
【问题描述】:
我正在尝试通过这样做来初始化一棵树:
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);
}
但是我遇到了分段错误。为什么会这样?我正在传递一个指向函数的指针,并在其中保留内存。有错吗?
【问题讨论】:
-
这个确切的程序是否存在分段错误?在哪一行?
-
为什么你们在尝试在其中编写整个操作系统之前不要学习 C...
-
H2CO3 是 ... 直接 :D 但正确 :)