First of all sorry for my English. Second I'm new in c and data structures.
I created a menu and put it in loop so that I could use it to make operations like insert, remove(all the tree nods), remove(one node), create(from a file) and so on. All the methods were working except the insert method. I can't see why because there is no compilation error. It insert only the first and last element on the tree. And if the strings have different sizes it stops running.
It ends the loop when I open the file and the loop in my menu.
The file has number starting from 0 to 9 and letters starting from a to z, and next to them it has a code, like this:
0 ----- 1 .---- . . a ..-.- b ..-.. . z .-
Here is the code:
struct treeB{
struct treeB *left;
struct treeB *right;
char letter[2];
char code[5];
}*root=NULL;
typedef struct treeB tree;
void insert(tree* aux){
//I create the tree and allocate the memory in the main
int flag=0;
tree *ptr, *father;
ptr=root;
if(root==NULL){
root=aux;
}else{
while(ptr != NULL){
if(strcmp(aux->code, ptr->code)==1){
father=ptr;
ptr=ptr->right;
}else{
if(strcmp(aux->code, ptr->code)==-1){
father=ptr;
ptr=ptr->left;
}else{
flag=1;
printf("\n The code %s already exists");
break;
}
}
if(flag==0){
if(strcmp(father->code, aux->code)==1){
father->left=aux;
}else{
if(strcmp(father->code, aux->code)==-1){
father->right=aux;
}
}
}
}
}
}