All of the "WORDS IN DICTIONARY: " parts are resulting in "0" but when i run the code on my computer trying both the "small" and "large" dictionary it seems to work perfectly. So what might be the problem? The way i made my size() function is as follows:

unsigned int size(void)
    // Open dictionary
    FILE *file = fopen(DICTIONARY, "r");
    if (file == NULL)
        return false;
    unsigned int count = 0;
    char character;
    // Insert words into hash table
    while ((character = fgetc(file)) != EOF)
        if (character == '\n')
    return count;

Pls note that i copy pasted this #define DICTIONARY "dictionaries/large" from the file speller.c into the dictionary.c file where my size() is made since i did not know how else to acces the used dictionary. Could that be the problem perhaps? that check50 doesn't know that in order to change the dictionary it has to change 2 places instead of 1 ?

  • 1. You are counting dictionary-file while you are asked to return the words count of your dictionary data-structure (hash-table). 2. Do not use #define DICTIONARY "dictionaries/large" - check50-dictionary can be located in other folder. – Rustam A. Nov 6 '19 at 18:07

By using DICTIONARY in your size() code, you have effectively hardcoded the name of the dictionary file. If you're using this technique, it should use the file that's actually passed to the speller program when it is executed.

RE: copying #define DICTIONARY "dictionaries/large from speller.c - this isn't necessary. When the program is compiled, all of the defines in speller become available to all the code in the program. However, if needed, it's always a good practice to put it in the source file where it's used.

Finally, while this technique will count the number of words in the dictionary file, think about it. If there's an issue between how load executes and how size executes (like opening the wrong file), the number of words loaded into memory by load() and the number of words counted by size() could be different.

Instead, it would be far more effective, efficient, and accurate to count the words processed in the load function for later use in the size function. Think about it. The main function of the size function is to return the number of words in the dictionary. There are no specific requirements about how to get that count.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .