I have one more questions about SPELLER. I've completed all my codes for load, check, size and unload. I'm now trying to debug all of them. It appears I have an error with my check function, which one is suppose to return true or false. I think this error is linked to the numerous false statements. Probably, confusion is there.
Actually I thought all cases were covered and if any of the returns were reached in the loop, the last false statement would be return. Should I rewrite my code in a way only one choice is made at the end of the loop between returning true or returning false?
Please, someone can explain me why this fault occur. I want to continue debugging my programs but now I'm just turning in circle.
There, you will find my code for CHECK and a print screen of my prompt command trying to run speller in gdb :
bool check(const char* word)
{
// initialize variable
int index = 0;
// Processing throughout word
for (int i = 0, n = strlen(word); i <= n; i++)
{
// pointing current to root
current = root;
if (isalpha(word[i]))
{
if (i == 0)
{
index = tolower(word[i]) - 'a';
current = root->children[index];
if (root->children[index] == NULL)
{
return false;
}
else
{
index = tolower(word[i]) - 'a';
current = current->children[index];
if (current->children[index] == NULL)
{
return false;
}
}
}
else if (word[i] == '\'' && i > 0)
{
current = current->children[26];
if (current->children[26] == NULL)
{
return false;
}
}
else if (word[i] == '\0' && i == n)
{
// if is a completed word
if (current->is_word == true)
{
return true;
}
else return false;
}
}
return false;
}
}
and there, print screen of my prompt :