Beside the problem with while(isspace(ch));
that should probably be replaced with while(!isspace(ch));
you need to add a null character at the end of your string before sending it to your insert()
function and this function should also return a new value for the root variable:
string[i]= 0;
i=0;
root=insert(string,root);
You should also make sure that the value of i doesn’t get higher than 19 in order to not overrun the length of the string buffer.
1
solved Segmentation Fault in Binary Tree Program