I have tried to programme a trie for pset5, but every time I run the spellcheck it isn't finding any misspellings and I can't work out why. Any help would be appreciated.
typedef struct node
{
bool is_word;
struct node*children[ABSIZE+1];
}
node;
unsigned int dicsize=0;
node* root=NULL;
bool check(const char* word)
{node* nextNode= root;
unsigned int i=0;
unsigned int m;
do
{
m=word[i];
if (m>=65 && m<=90)
{
m|=32;
}
if (( m>=97 && m<=122) || (m='\''))
{
if (m=='\'')
{
m = ABSIZE +AOFF;
}
if (nextNode->children[m-AOFF] == NULL)
{
return false;
}
else
{
nextNode = nextNode->children[m-AOFF];
}
}
i++;
} while(m !='\0');
return nextNode->is_word;
}
bool load(const char* dictionary)
{
FILE* fp= fopen(dictionary,"r");
if (fp==NULL)
{
printf("cannot open file");
return false;
}
root = malloc(sizeof(node));
unsigned int m = 0;
node* nextNode = root;
do
{
m=fgetc(fp);
if (m !='\n' && m!=EOF)
{
if (m=='\'')
{
m = ABSIZE +AOFF;
}
if ( nextNode->children[m-AOFF] == NULL)
{
nextNode->children[m-AOFF] = malloc(sizeof(node));
}
nextNode= nextNode-> children[m-AOFF];
}
else if (m=='\n')
{
nextNode->is_word = true;
dicsize++;
nextNode=root;
}
} while ( m!=EOF) ;
fclose(fp);
return true;
}