I am getting different results when using check50 versus using diff -y [output.txt] keys/[text] to test my code. The difference is always in WORDS IN DICTIONARY and mine is always off by exactly +1 word.

The version of my code that fails check50 passes the keys test (SOLUTION A in the code below), and the version that passes check50 fails the keys test (SOLUTION B). Here is my code for the load function with SOLUTION A implemented:

// Loads dictionary into memory, returning true if successful else false
bool load(const char *dictionary)

    /* SOLUTION B: 
    / Reads first word in the dictionary
    fscanf(dict, "%s", dict_word);*/

    while (feof(dict) == 0)
        /* SOLUTION A:
        / Reads word in the dictionary*/
        fscanf(dict, "%s", dict_word);


            // Update wordcount
            wordcount = wordcount + 1;

            /* SOLUTION B: 
            / Reads next word
            fscanf(dict, "%s", dict_word);*/

        // If word does not meet requirements it is not loaded into the dictionary

    // All words are read and stored
    return true;

This is the result of check 50 using SOLUTION A. The only difference seems to be that I always have 1 extra word in my dictionary, but if I test SOLUTION A with, for example, diff -y student.txt keys/her.txt, I get:

WORDS MISSPELLED:     767                                       WORDS MISSPELLED:     767
WORDS IN DICTIONARY:  143091                                    WORDS IN DICTIONARY:  143091
WORDS IN TEXT:        18402                                     WORDS IN TEXT:        18402

which shows that I counted the words in the dictionary correctly. SOLUTION B, on the other hand, as per the code, (incorrectly) results in the last word in the dictionary being unread, i.e., I am one word short, which actually passes check50 but in a roundabout kind of way.

I am not sure if I should submit the 'incorrect' speller to pass check50, or if there is something I'm missing in the code. Given these assumptions for check50's dictionary:

You may assume that any dictionary passed to your program will be structured exactly like ours, alphabetically sorted from top to bottom with one word per line, each of which ends with \n. You may also assume that dictionary will contain at least one word, that no word will be longer than LENGTH (a constant defined in dictionary.h) characters, that no word will appear more than once, that each word will contain only lowercase alphabetical characters and possibly apostrophes, and that no word will start with an apostrophe

I'm doubtful that there is a 'trick' word that should not be read but is passing my load function's checks, but I could be wrong. (For reference, the only checks I did for dict_word involve LENGTH.)

Any advice or help would be appreciated, and thanks in advance!

  • check out this short starting around 7:20 to learn what is the problem with while (feof(dict) == 0) Apr 21 '20 at 23:11
  • Thank you! The video was really helpful; I didn't know feof returned TRUE even after reading the last string. I have since switched to using fgets and I am now redoing the checks. Cheers!
    – AlyAsh
    Apr 22 '20 at 19:32

You must log in to answer this question.

Browse other questions tagged .