ok,
Code:
void tree_add_child (parent, child)
tree *parent;
tree *child;
{
int i;
parent->number_of_children++;
// segfault in the line below
parent->children = (tree **) realloc (parent->children, sizeof (tree * [parent->number_of_children]);
if (parent->children == NULL) exit (-1);
parent->children[parent->number_of_children] = child;
}
ok, the function is simple, each struct "tree" has a list of children, its a pointer to a array of pointers to other struct "tree"s, this should increase the number of children, then use realloc to make a extra space, then insert the pointer at the end.
Code:
typedef struct _tree {
int number_of_children;
_tree **children;
} tree;
the main function inits multiple tree struct, with the children set to NULL, and number to 0. Then this function is called to add children to 1 tree struct, it works fine for the first 3, but on the forth it segfaults at the realloc line, i been trying for days but cant seem to find out why, or make it go away. any ideas on why its doing this?, thanks.