When running speller with the small dictionary and ralph.txt as the text, my program correctly outputs the misspelled words and outputs the statistics (i.e. time in load, number of words in dictionary etc.). It also behaves this way for a large text (i.e. kjv).

I have also tested with a dictionary containing 2572 words and the program manages to produce a correct output for ralph. But for kjv it outputs "MISPELLED WORDS" followed by some words and then has to be ended with ctrl c.

This also happens when I run the program with the large dictionary. However, the only output is "MISPELLED WORDS" for both ralph and kjv and I have to press ctrl c to end the program (see below)

~/workspace/pset5/speller/ $ ./speller dictionaries/large texts/ralph.txt



what could be the problem? Help would be very much appreciated!

(I have completed all four functions and the program passes check50 but given the output problem described above, the program can't be working correctly).

EDIT: code removed to comply with academic honesty

  • Without seeing code, here's a scenario I would invent. If all the 143+K words are going into one hash index then it just takes a really really really long time to traverse. Since "Textfile" and "Wiggum" (first fail words) are way down in the alphabet, make sure check starts at the correct hash index. What happens with a one word text file of your own creation against the large dictionary? Does apple work fairly quickly, but zebra takes forever? There's always debug50, and valgrind has been known to give excellent hints. Jun 25 '17 at 22:23
  • After MISSPELLED WORDS, there's one call to check for every word in the text (there's also a call to size before the next guaranteed output). As you seem to run into an infinite or near-infinite loop, you might have a) implemented a hash-map and did not separate the linked lists well, or put everything in a single hash-map entry, or b) have created a pointer loop, maybe by using free on a node that's still in use. I'd try valgrind on input that does finish first.
    – Blauelf
    Jun 26 '17 at 12:37
  • @DinoCoderSaurus thanks for your comment :) I tried running the program with a text file of one word. For both apple and zebra the same thing happened (i.e. only "misspelled words" output). I also ran the program with valgrind and there were a lot of errors and memory leaks. These seem to be related to unload. I'm not sure where I've gone wrong in unload in that case then. I've added my code to my question.
    – Jennah
    Jun 26 '17 at 15:37

Is this right new_node -> next = hashtable[hash];? new_node is pointing to the head of the list and then hashtable[hash] -> next = new_node; head of the list is pointing to new_node. As @Blauelf said, pointer loop.

  • Thank you both so much!! Modifying that line of code solved the problem. It seems really obvious now that it has been pointed out to me.
    – Jennah
    Jun 26 '17 at 16:57

You must log in to answer this question.

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