hey guys,

Im new to C and having a bit of problems inserting into a recursively defined BST. it seems to work ok inserting 3 or 4 items but any more than that and it starts to make duplicates and do wierd things, i have a feeling it could be a very simple obvious mistake but I just cannot find it. I have included the insertion code and how the tree is defined below:

Thanks in advance for the help!!Code:struct bstnode{ char *key; bst left; bst right; }; bst bst_insert(bst b, char *s){ if( b == NULL ){ bst result = emalloc(sizeof * result); result->key = emalloc((strlen(s) + 1) * sizeof s[0]); strcpy(result->key, s); return result; } else{ if( strcmp(b->key, s) == 0 ){ return b; } else if( strcmp(b->key, s) < 0){ b->right = bst_insert(b->right, s); } else if( strcmp(b->key, s) > 0){ b->left = bst_insert(b->left, s); } } }