Hot answers tagged

1

I see a few problems in the code that are causing problems. First, table[] is not initialized. That means that all the pointers in the array contain garbage data instead of NULL when the program starts. Second, there's this: while (fscanf(file, "%s", word) != EOF) { fscanf(file, "%s", word); This is executing two sequential reads. ...


1

You cannot free the memory in load because it needs to be used throughout the entire program. It needs to wait until the program is done and then can be freed in unload. It also appears that you have a misconception about how the memory is used, so I'll try to explain it in that context. When memory is malloc'd to new_word in load, the memory is allocated, ...


1

You shouldn't free memory in load(). That's where unload() comes in. All of the memory allocated in the code should be freed in unload() only, except very specific cases (this was answered by a mentor in discord). Since you didn't post the rest of the code, I'm not sure if that's what you tried in unload() but let me know.


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 ...


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