0

I really need your help because I'm stuck on pset5 for so many days:(

  1. I don't know for what reason but my program always sees one extra word in the dictionary! I mean even in the example with austinpowers.txt my program has found 143092 words instead of
    1. And it's also seen from my cs50 check(https://sandbox.cs50.net/checks/1a48913b86fa49278c8b50813f7141ee) But the point is that when I use my own small dictionary, my program shows real number of words in the dictionary. But when I'm working with bigger ones, it always +1 Could anyone help me to figure out what's the problem???
  2. How can I reduce the time needed for checking. Cause mine takes 0.78 comparing to staff's 0.00 in the example with austinpowers.txt

  3. Has anyone tried to put the words in the dictionary in alphabetical order(using hash tables)? How have you managed to do this?? Because I've tried to do it(actually it worked properly) but the running time of my program was about 15 secs O_O When I got rid of that order, it worked much faster

my code: speller.c http://paste.ubuntu.com/23051675/

dictionary.c http://paste.ubuntu.com/23051677/

dictionary.h http://paste.ubuntu.com/23051678/

1 Answer 1

2

"Ready, Fire, Aim!" Classic error. The logic of your code is this: read a line (word) from the dictionary, then process it, and then check for EOF. The problem with this is that the EOF isn't detected until it is actually processed. After reading the last word, the pointer can and will go right up to the EOF without detecting it. It will only trip the EOF detection on the next read. Since it loops one more time to detect the EOF, it processes that last node with no data. Thus, the extra word.

The EOF detection should be done just after the read, or the read should be incorporated into the while statement with appropriate tests to detect EOF on the return value from the read.

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

You must log in to answer this question.

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