I have a dictionary file(containing words only lower case and apostrophe) that is loaded as a trie tree.
I have a check function which checks the words of file if they exist in the trie tree, regardless of letters cases.
Everything works fine except that apostrophe's word are always found as misspelled.
Here is my function
bool check(const char *word)
{
// creat arrow to follow letters
NODE* arrow = root;
// for every letter in word
for (int i = 0, length = strlen(word); i < length; i++)
{
int index;
if(word[i] == '\'')
{
index = 26;
} else {
index = tolower(word[i]) - ASCII_DIFFERENCE;
}
// if NULL? creat a new one and move arrow to new child
if (arrow->child[index] == NULL)
{
return false;
} else if (arrow->child[index] != NULL) // not null?
{
arrow = arrow->child[index];
}
}
return arrow->isWord;
}
my struct :
typedef struct NODE
{
bool isWord;
struct NODE* child[ALPHA_SIZE];
} NODE;
definitions
#define ASCII_DIFFERENCE 'a'
Any help is appreciated.