FULL CODE http://pastebin.com/6bdVTyPt
My tree code was perfectly working until i found out i needed to validate the id that its not text so it had to be string
insertion function
string compare of 90 and 129 returns 8
tried to use (atoi) and compare as integers does not work
any help appreciated
thank you
heres the insert function using atoi instead of strcomp
http://pastebin.com/yeuktyAF still not working
insertion function
struct node * insert2(struct node *root, char x[],char id[])
{
if(!root)
{
root=(struct node*)malloc(sizeof(struct node));
free( root->data );
free( root->id );// free previously allocated memory, if any
root->data = strdup( x ); // malloc and copy
root->id=strdup(id);
root->left = NULL;
root->right = NULL;
// printf("1\n");
return(root);
}
printf("string comp %d of %s of %s\n",strcmp(root->id,id),root->id,id);
if((strcmp(root->id,id))>0){
root->left = insert(root->left,x,id);
printf("go left\n");
}
else
{
if(strcmp(root->id,id)<0){
printf("go right\n");
root->right = insert(root->right,x,id);}
}
return(root);
}