0

Speller is showing an incorrect list of misspelled words and is reporting an incorrect number for both the misspelled words and text counts. This issue occurs with both the code I got from the pset zip file and with the staff's version.

I narrowed the problem down to the following: If the last word in the text file is a misspelled word but does not have and eol character then the misspelled list and the misspelled and text counts are incorrect. If the last word is not a misspelled word then only the text count is short by 1.

If the last word in the text file is a misspelled word and has an eol character at the end (effectively creating a blank line as the last line in the file) then the misspelled word list is correct and the misspelled and text counts are correct.

Attached is a screenshot showing the output from the pset.zip and the staff's versions of speller.

Here's the content of my test files:
Dictionary:
apple
bee
cat
don't
ever
fishing
gentle
handsome
ignite
jump
kangaroo
llama
mars
nun
opiate
paris
quiet
rhino
star
stare
start
turtle
umbrella
vexing
xylophone
zoo

Text:
For
bee
spoiler
start
stare
star
don't
try
trust <--no eol should follow this word to produce the problem.

Note: The format of one word per line is intentional

At this point, my code doesn't pass Check50 but I can't tell if it due to anything I've done or if the problem is this bug.

Thanks.

output screenshot

1

The last word in the text file must have some "separation" between it and EOF. speller reads text (mainly) here for (int c = fgetc(fp); c != EOF; c = fgetc(fp)). When EOF is encountered, control proceeds directly to unload and return. If the last word "includes" the EOF (as in your example above) it will never check it. Whether it's a bug or not is immaterial, it is a fact. One can assume that the text files used by check50 include a final "something" (whether newline or '.' or anything), just as the supplied text files do. Sorry to say, if program is not passing check50, it is a defect in dictionary, not speller.

2
  • I agree. I didn't think about the need for a final punctuation mark (or any non-alphanumeric character). I interpreted the specification for this pset as stating that you could give it any file with text without regard for how it ends. Thanks for pointing this out.So now I have to figure out why it's not passing check50. Mar 8 '17 at 3:07
  • The supplied text files all have a newline as the last character. If you use vi you can see this (displayed as '$') with :set list. Or from the command line try cat -e textfilename. This will also display newlines as '$'. Mar 8 '17 at 3:07

You must log in to answer this question.

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