I have a binary tree program that is trying to retrieve a name. I've already inserted names into the tree correctly and can see this at output. Now I'm trying to check for a name in the tree and calling that input "key". My program wants to take that key and compate it with data found from the function getName(). My program crashes at getName() in the strcpy line: Here is my code for the recursive retrieve:
bool BST::recurRetrieve(const char *key,data& aData,int index)const
{
if(items[index].empty)
{
return false;
}
items[index].data.getName(temp); //char *temp
if (strcmp(temp,key)== 0)
{
aData = items[index].data;
return true;
}
else
{
if(aData < items[index].data)
recurRetrieve(key,aData,2*index+1);
else
recurRetrieve(key,aData,2*index+2);
}
}
This is my code for getName():
void data::getName (char * name)const
{
/*name = new char[strlen(name)+1];*/
strcpy(name, this->name); //program crashes right after this step
}
I'm really hoping this is a matter of syntax, (in which case I'm a goof), instead of my algorithm being really wrong. Thanks for looking. I'm going insane :S