0

I have been tearing my hair out over the speller for days now, and I think I'm losing my mind - lol.

I followed along with the short videos for linked lists and hashtables, and wrote some simple functions that (seemingly?) allowed me to create, and insert into linked lists, then put the lists in a hashtable array. I also wrote a search function that seemed to successfully find words that I had hashed an added to the hashtable. Great! So I adapted them to Speller, and am now finding that in this context they puzzlingly no longer work.

I think that my load and create functions are the culprit? What's curious to me is that, to debug, after loading the dictionary items into the hashtable, I iterate through it, and print the dictionary words to the console. But later, in my check function when I iterate through the same linked lists, the pointers are pointing to gibberish.

I am using a simple 2 word dictionary and text both with "time" and "product" in them to test my code. I haven't accounted for case yet, I was just trying to get basic functionality first.

Here is a link to my code: https://gist.github.com/tkansa/74d4efb526d90b42e032f9f5707724e6

and here is my output to console where I prefaced the output with the function that it's being called in and iterated over the linked lists, As you can see, the load function has the dictionary word, but they get "lost" when I try to access them in other functions:

Load: The hash number: 23627

Load: The dictionery word: time

Load: The pointer: 29041232

Load: The hash number: 111188

Load: The dictionery word: products

Load: The pointer: 29041264

MISSPELLED WORDS

Check: The hash number: 23627

Check: The dictionary word: I (should be time)

Check: The pointer: 29041232

Check: The text word: time

Check: The hash number: 111188

Check: The dictionary word: I (should be products)

Check: The pointer: 29041264

Check: The text word: products

WORDS MISSPELLED: 2 WORDS IN DICTIONARY: 2 WORDS IN TEXT: 2 TIME IN load: 0.00 TIME IN check: 0.00 TIME IN size: 0.00 TIME IN unload: 0.00 TIME IN TOTAL: 0.00

I'm probably overlooking something really obvious, but I've been staring at this code so long I can't even see it any more - lol.

Any help would be SUPER appreciated!!!

1
  • Okay, I think the struct where I was defining my node to hold the word (and the pointer) was wrong. Should be char word[LENGTH+]; not char* word; That seems to have fixed some of the problems. I'm going to tinker a sec more to confirm. Then I will close this. – 1fatcat Aug 12 '17 at 22:14
0

Yes, per my update above I was defining my node incorrectly for the linked list. Now everything works like a charm!!!

You must log in to answer this question.

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