When I test my dictionary manually with the large dictionary, there are no issues. I even get the correct mispelled words. But if I use check50 or even test with smaller dictionaries, it doesn't seem to load (or possibly count) all the words in the dictionary and hence doesnt pass check50.
The behaviour is confusing me. For example, if a dict is less than 12 words, it only loads 1 word. If it is 11 words in the dict, it says 12, Even at about 78 worss, it still says 12. But when I load the large dict it correctly says 143091 wods loaded.
Clearly I have stuffed something up, I just can't figure out what. My best guess is the hash function I found. I grabbed a hash function for the net as a temporary solution because I wanted to try and make my own, but before I muddle with hash functions, I want to make sure the rest of my code is fine.
This is my load function:
bool load(const char *dictionary)
{
FILE *fp = fopen(dictionary, "r");
if (fp == NULL)
{
printf("Could not open %s.\n", dictionary);
return 1;
}
node *head = hashtable[0];
char word[45];
while (fscanf(fp, "%s", word) != EOF)
{
node *new_node = malloc(sizeof(node));
if (new_node == NULL)
{
unload();
return false;
}
else
{
strcpy(new_node->word, word);
new_node->next = head;
head = new_node;
unsigned long hashed_number = hash_word(word);
hashtable[hashed_number] = new_node;
}
}
return true;
}
I must be doing at least something right, because it works with the large dictionary. Any help would be appreciated.