2

In your load, when your hashtable[key]->next isn't null, you do this: new_word->next=head; head = new_word; what is head at this point? Last time you set it, it was for the first node in your linked list. As such, you are overwriting the first node in that bucket and end up throwing away some words. Shouldn't you be using hashtable[key]->...


2

Also, implement size, which is a pretty simple function, and see how many words your function loads. My original load function only took in the first word, even though it had seemed like it would work fine when I wrote and reviewed it.


2

I think you should just follow the steps described, write your code. Compile it. Run it. If it runs without errors or segmentation faults keep going to the next function. If you want though to be sure you could use gdb and run your program line by line. If you see that it repeats the reading of the words in the dictionary, and it executes the commands it ...


2

The issue is time. There's nothing wrong with the server for pset5. (Don't know if there are pset6 issues, but that's a different situation.) While your program may work, it is slow. When I ran your code, it was taking about 37 seconds to run with holmes.txt as input. That's on my system with minimal load and a solid state drive. Run it on a system with a ...


2

On some versions of C, you cannot declare a global variable index if you include <string.h>. Apparently the check50 server has such a version (and the IDE does not). There is a comment about it in the answer to this post. As an aside, some C implementations (BSD-based) define an index function in string.h which may also cause a problem. Use of this ...


1

I'm surprised it didn't seg fault. The hash function generates results > N. That means that it's creating entries in the table[] array beyond it's range. When unload runs, it's not finding the table entries that were created out of range. As for the discrepancy in the word counts, does your sample text test file have a blank line at the end? It needs to....


1

I believe the problem might be here: for (int i = 0; i < N; i++) { //temp points to what table points to temp = table[i]; //cursor points to what table points to cursor = table[i]; do { //cursor goes to the next node cursor = cursor->next; free(temp); } while (cursor != NULL); } Take a look at the ...


1

The unload function is intended to do all the freeing. When this line free(ptr); executes in the load function it is freeing the root node. Why? last line feed of last word does this ptr = root;. Boom, gone. The free(ptr) in check will cause problems when you move on to unload. Once the root node is free'd, you do not have access to any other nodes.


1

I see a couple of problems in the load function. For each new word in the dictionary, don't you want to start crawling the trie at the root node? When you create a new node here next->children[place]=makeNode();, don't you want the following letter to "go into" that new node (ie shouldn't next be the new node on the next iteration)? Perhaps create a ...


1

You're on the right track - there is something wrong in load(). It's a subtle logic problem. When you process each character, the following line is processed: strider = strider->children[index]; But what happens when you're processing '\n'? At best, it's putting another step in the linked list for the word. Shouldn't it instead be setting is-word? ...


1

Meanwhile I was able to make the program work, it runs nicely now and passes check50 and valgrind. The problem was fgets and eof. I replaced fgets with fscanf which solved the problem with the misspelled words. I am not very sure why but apparently this is because fgets ignores whitespace. The segfault problem was solved by adding another feof loop condition ...


1

This may seem a bit mean, but there are serious problems with your load logic. First, root was never initialized after malloc. Next, you are using root as a cursor to walk through the trie to load each letter of the word. By doing this, you lose the base of the trie. Each word ends up linked to the end of the previous word. After the dictionary is loaded, ...


1

Its a problem many are facing for now. I also can't get pset6 checked by check50. Also it hasn't been graded for over 1 week. The problem is on the server side, not with your code. Wait for some more days or even keep checking with check50 in week days, maybe the servers will be less busy then. Meanwhile start the new week and submit your code if you feel ...


1

Not really. If you have allocate memory for a node that represents the letter 'v' as the first letter of a word, then according to the implementation, this node has an array of node children each of which represents a letter that comes right after 'v' in that word. For example: #define SIZE 26 typdef struct node { bool isWord; struct node *children[...


1

Here are some pointers in the right direction: The large dictionary is hardcoded. Should be using parameter passed to load() as the dictionary. All words are hashing to 0 because word is empty. (new->word vs. word) Word count is off by 1. Code reads a line from dictionary file, processes it, and then checks for EOF. This results in one extra word in the ...


1

Here's a big red flag. The following line is near the bottom of the check() function. next_node -> is_word = true; In every dictionary word that it checks, it will set is_word to true for every letter that it moves across in the trie. The check function should not make any changes in the trie, it should only read the trie data. It looks like that ...


1

You need to try with different files and different dictionaries. Try a dictionary with the words: bar foo and a text with: the foo foo's bars bar's bar Do you correctly report 4 misspelled words? Try running with the small dictionary and the text: cat cats caterpillars caterpillar Do you correctly report 2 misspelled words?


Only top voted, non community-wiki answers of a minimum length are eligible