In my dictionary.c file, I declared my own function called trieNavigate(), whose code is below. I use it for loading and for checking, and so it returns a bool and accepts 3 parameters: a char (that is the character I use to navigate the trie), the "trieCrawler", a pointer to a trieNode, and a bool that tells the function if it is supposed to create a new trieNode if it tries to navigate to one that doesn't already exist. The problem is that when I am checking, it returns false when bool createNodePath is false, even if the node it tries to navigate to exists. I'm not sure if this code is the problem, or if the problem lies in my implementation of load() or check().
Please help.
bool trieNavigate(char c, trieNode *trieCrawler, bool createNodePath)
{
char stringOfC[2];
stringOfC[0] = c;
int letterValue;
if (strcmp(stringOfC, "\'") == 0)
{
letterValue = 26;
}
else
{
letterValue = c - 65;
}
if (trieCrawler->lettersAndApos[letterValue] == NULL)
{
if (createNodePath == true)
{
trieNode *newTrieNode = malloc(sizeof(trieNode));
newTrieNode = NULL;
trieCrawler->lettersAndApos[letterValue] = newTrieNode;
trieCrawler = trieCrawler->lettersAndApos[letterValue];
return true;
}
else
{
return false;
}
}
else
{
trieCrawler = trieCrawler->lettersAndApos[letterValue];
return true;
}
}