New answers tagged

0

This is a bug well hidden in plain sight. ;-) If you traced the program in debug, it runs all the way through to the unload() function, inside the while loop. It's failing when it hits the end of the first linked list that it processes. This is a big clue. If you look closer, you see that when the code gets to the end of the first linked list, the address ...


1

The seg fault lies here: char *term = NULL; while(fscanf(f, "%s", term) != EOF) { fscanf(f, "%s", term); node *nd = malloc(sizeof(node)); if (nd != NULL) { strcpy(nd->word, term); Note first that the pointer term is set to NULL. That means that no memory is allocated to that ...


1

For starters, the program doesn't actually compile without error. It's probably compiling in your environment with a warning about an unused parameter in the call to load(). In most people's environment, that would produce a warning about the unused parameter of dictionary in the signature which would be treated as an error. The root cause of that is this ...


0

on observing the check 50 and debug50 results, I realized that the problem was in the unload function. solution: // Unloads dictionary from memory, returning true if successful, else false bool unload(void) { node *tmp = NULL; node *cursor = NULL; //iterating over each linked list in the hash table. for(int i = 0; i < N; ...


1

The first big problems I see are in check(). Look at this line: while(cursor->next != NULL) This is going to result in every other node being skipped, among other anomalies. It should be checking cursor, not cursor->next. I'll let you figure out why. Next, there's the two free(cursor) statements in the check function. Even though you created a ...


1

It looks like most, if not all of the issues arise from one problem. In the load function, near the bottom, I found this: free(newnode); What happens when you free the node that you just created??? Doesn't it destroy the node that was just created at that address??? Copying the address to another location doesn't copy the node. So, if you have a dozen ...


1

It looks like an intermittent problem that's going to rear it's ugly head depending on what's in memory and what was in memory before. Since your whole code wasn't posted, I looked fairly closely at the load function. This jumps out at me: for (int i = 0; word[i]; i++) { w->word[i] = word[i]; } It looks like the code is trying to ...


Top 50 recent answers are included