Hi All. I got this code. I would like to compare two strings. When the string is found, I want it to return where it found it in a Binary Tree.
My code receives a string (test) and well I get an error on the line shown.
I get a strange error here ( Unhandled exception at 0x0F3DF950 (msvcr110d.dll) in Project1.exe: 0xC0000005: Access violation reading location 0x00000000.)
Please help and another way to do this?
Code:
NodePtr find2(NodePtr root, char test[])
{
if (root!=NULL)
{
int cmp1=strcmp((root->left)->data,test);// error code
int cmp2=strcmp((root->right)->data,test);
if (cmp1==0)
return root->left;
find2(root->left,test);//transverse the tree
if (cmp2==0)
return root->left;
find2(root->right,test);//transverse the tree
}
return 0;// return 0 if not found
}