hey all,
having trouble with a part of my program that puts a node into a binary tree. i havent put the whole code here b/c that would be to big.
im using gcc on unix.. After using gdb it tells me that there is an error on the line ive marked in the strcmp() function.
ive put in a fprintf statement to see if the current word is null.. but its not. and the "newWord" variable is definatly not null..
(its a copy of the string value of the node im adding.. it could be replaced with "tempWord->string")
it works for about the first 200 nodes then core dumps for some unknown reason.
nobody i know seems to have any idea.. anyone got any ideas?
by the way.. how do u do that code thing again?
------------------------------------------------------------------------------
if(headOfTree->firstWord == NULL)
{
headOfTree->firstWord = tempWord;
} else {
currentWord = headOfTree->firstWord;
while(loop && currentWord != NULL)
{
fprintf(stderr,"%p\n", currentWord);
if(strcmp(currentWord->string, newWord) < 0)/*error*/
{
if(currentWord->childTwo == NULL)
{
loop = FALSE;
currentWord->childTwo = tempWord;
} else
currentWord = currentWord->childTwo;
} else if(strcmp(currentWord->string, newWord) > 0)
{
if(currentWord->childOne == NULL)
{
loop = FALSE;
currentWord->childOne = tempWord;
} else
currentWord = currentWord->childOne;
} else {
loop = FALSE;
}
}
}
--------------------------------------------------------------------------------