Hi, help please!
I have a struct containing an array of pointers
to structs containing Binary Search Trees
with nodes containing structs.
... <*sigh*> I hate C soo much... put work wants it to be in C.
I can set the struct of BST's just fine, and keep it around, and I can set the innermost struct values. My problem is keeping those innermost values once I'm outside the function that puts them there.
void function(Struct struct, int i, int k)
{
Array array;
array = InitArray();
array->key = k;
struct->array[i] = &array;
}
void otherFunction(Struct struct, int i, int key, DStruct data)
{
Tree tree;
tree = InitTree(key, data);
(*struct->array[i])->bst = tree; //works, but only keeps value inside current function
//(*struct->array[i])->bst = &tree; //incompatible pointer type... and Seg fault as soon as output is run
PrintInorderTreeWalk((*struct->array[i])->bst); //works, but it's only one node long
}
void anotherFunction(Struct struct, int i)
{
if(struct->array[i]) != NULL) //works
{
if((*struct->array[i])->bst != NULL) //Segmentation Fault for 'working' assignment above.
PrintInorderTreeWalk((*struct->array[i])->bst); //seg fault if the if stmt is commented out.
}
}
I want that commented out command to actually, but I'm not good enough with the pointers to get it to.
And I realize I'm not giving a whole lot of code here, but I think it gets the important parts across. I'm not really allowed to put much of it out anyway, but I could change everything to struct A, B, C, etc if needed. It's just huge.
Thanks for the help!