Getting a Segmentation fault
This is the beginning of an avl tree project. I've never heard of a segmentation fault before now, but after some reading I guess is has something to do with read/writing is a specific point in memory that the OS doesn't allow? Well I'd really appreciate if someone could point out my error in this part of the program, I'm sure it's probably something simple. I believe the offending line is the first line of the insert function.
Code:
#include <stdio.h>
typedef struct node{
struct node * left;
struct node * right;
int value;
} NODE;
typedef struct tree{
NODE * root;
} TREE;
/*Function declarations*/
void insert(NODE * node, NODE * root);
int getheight(NODE * node);
int main(void){
TREE tree;
NODE rt;
rt.value = 3;
rt.left = NULL;
rt.right = NULL;
NODE nd1;
tree.root = &rt;
tree.root->value = 3;
/*declare new node and put in tree*/
nd1.value = 1;
insert(&nd1, tree.root);
return 0;
}
void insert(NODE * node, NODE * root){
if ( node->value > root->value && root->right == NULL){ //<----this ???
root->right = node;
}
else{
insert(node, root->right);
}
if ( node->value < root->value && root->left == NULL ){
root->right = node;
}
else{
insert(node, root->left);
}
}