8 votes
Accepted

(pset5) valgrind - 1 block not freed

Hmmm..... 568 bytes in 1 block.... sounds like a file pointer. Did we forget to close an open file somewhere???? ;-) Side note: valgrind usually tells you how you can get more information, ...
user avatar
  • 63.4k
7 votes
Accepted

Try to use trie in pset5

You can do it. It's a good practice to initialize the values to something, NULL in this case, to prevent any garbage value remaining in the memory from messing with the execution of the code. I don't ...
user avatar
  • 1,369
3 votes

Try to use trie in pset5

should I let the array point to NULL when I define the struct in the beginning? If your struct definition looks like this struct node { struct node *arr[27]; }; then you actually can't assign ...
user avatar
  • 17.4k
2 votes
Accepted

Could not load dictionary in cs50 pset6

Try removing the semicolon after your if statement. if(d == NULL) { printf("Could not load %s\n",dictionary); return false; }
user avatar
  • 1,317
2 votes
Accepted

Trie Spellchecker unload() - two allocs not freeing

You overlooked something. Here's a hint. What is the integer value of ' - 'a'? Or, subtract the ASCII value of 'a' from the value of an apostrophe? I'm actually surprised that your code isn't ...
user avatar
  • 63.4k
2 votes

how do I malloc nodes for use in a trie data structure

For the structure given by node above, memory can be allocated using the following syntax: LETTERNODE * lettterptr = malloc(sizeof(LETTERNODE)); or more universally: struct node * letterptr = ...
user avatar
2 votes
Accepted

Segmentation Fault in pset5

Jessup: There's a few things here: 1) If you're calling a recursion on a function with a return value, like in this case, you should return each recursive call. This has nothing to do with the ...
user avatar
  • 1,677
2 votes
Accepted

Initializing multiple variables inside a for loop

Why not just create an array of pointers to nodes? struct node* foo[27]; Then you can use a loop to assign NULL to each element by indexing through the array. If this answers your question, please ...
user avatar
  • 63.4k
2 votes
Accepted

Problem Set 5: Speller, Segmentation fault

Your error originates a lot earlier in the code. Look at the first two lines in your do loop: a = fgetc(file); int hash_value = hash(word); Your first problem is that you only read a single ...
user avatar
  • 63.4k
2 votes
Accepted

Pset5: problem with inserting words into nodes

I think the problem might be here: char* word[LENGTH + 1] = {}; If you use the star and the brackets, you are declaring an array of pointers to chars. Try instead just char word[LENGTH +1] = {}; ...
user avatar
2 votes
Accepted

PSET5 Dictionary - error : Could not open texts files

Yes, you're not giving the right parameters. There are two ways to invoke speller: ./speller <file_to_test> ./speller <dictionary_file> <file_to_test> You've been invoking with ...
user avatar
  • 63.4k
2 votes
Accepted

Problem in my unload function (double free or corruption)

one block of memory can be pointed at by many pointers. this is exactly what happens when you allocate memory for one pointer, then set the value of another pointer to be the same as the first pointer'...
user avatar
  • 17.4k
2 votes
Accepted

pset5 trie: What is the boolean-data value in the root node if the dictionary has one-letter words?

The trie starts at one root node. This node will always have the is_word bool as false because the root node doesn't actually represent a letter. For a one letter word, say a, you would first move one ...
user avatar
  • 63.4k
2 votes
Accepted

Speller.c finds some words, but says that correct words are mispelled PSET 5 - Speller

One problem is here: word[strlen(word) - 1] = '\0'; You would need to "null out" the newline if using fgets. Not so with fscanf, it does not include the newline. From man fscanf: s Matches a ...
user avatar
2 votes
Accepted

too many misspelled words

Do not replace the value of root within check. That way, you replace your trie with an empty one. Here in Germany we sometimes call that a "Guttenbug", a bug by faulty copy&paste. (Semi-funny ...
user avatar
  • 20.7k
2 votes
Accepted

pset5 speller Invalid write of size 1

Did you know that sizeof(word) returns the length of the word variable? That's right, 8 bytes on a 64-bit system. The variable stores a memory address of the first byte of the string (stored somewhere ...
user avatar
  • 20.7k
2 votes
Accepted

Pset5 - Valgrind causes 9544106 errors, Uninitialised value was created by a heap allocation

The issue lies in how you are initializing your nodes. for (int i=0; i<27; i++) { trav->next[x]=NULL; } What is x on that line? Pay special attention to your counting variable in the loop. ...
user avatar
  • 18.3k
1 vote

Speller - Tries - Check function does not work

A couple things I see right away... You malloc space for root here in check. However, you shouldn't need to do that. You probably already did this in load. The logic of check is such that you ...
user avatar
  • 1,424
1 vote

Problem in my unload function (double free or corruption)

You are trying to free the same node twice. At the end of your freenode() function, you have the following code: if(n != NULL) free(n);. Remember that this is a recursive function. freenode() will ...
user avatar
  • 63.4k
1 vote
Accepted

pset5: I am leaking all of my memory. What am I missing?

I haven't tested the code, but I have several observations. First, do you actually have the code fully working? If not, you really should focus on that first. Correcting memory leaks before getting it ...
user avatar
  • 63.4k
1 vote
Accepted

PSET5 - Help with Valgrind? error : "uninitialised value(s)"

Try using calloc instead of malloc (the syntax is slightly different, but you can google it, it's not difficult). The difference is that calloc initializes all the memory (in this case you might want ...
user avatar
  • 1,677
1 vote
Accepted

PSET5 - CHECK returning... nothing?

At the bottom of your code, there is a place where your function will not return anything. That's probably around line 93 in your program, the line that clang complained about. Now you need to follow ...
user avatar
1 vote
Accepted

PSET5 What LOAD really supposed to do?

Yes, the dictionary file is expected to be a file that contains a sorted list of words, one per line. Your mission is, indeed, to create in the LOAD function, code that will take those words and ...
user avatar
  • 63.4k
1 vote

pset5: dictionary not loading correctly

Simple problem. Your word_count is declared locally in the load() function. As soon as you leave load, it disappears. It does not exist outside of load. The word count is displayed in the call to ...
user avatar
  • 63.4k
1 vote
Accepted

pset5 speller valgrind still reachable

Figured it out! The problem was on dictionary.c:179. I replaced return freeMem(pntr->next[i]) with freeMem(pntr->next[i]) and now valgrind is happy!
user avatar
1 vote
Accepted

Dictionary.c problems (still not working)

THis should get you started. I ran your code using a tiny dictionary (cat, cater, car) as both the dictionary and the test text and was able to duplicate the seg fault. I located the following issue. ...
user avatar
  • 63.4k
1 vote
Accepted

Valgrind errors at the end

It looks to me like you have a much larger problem than you think. It's reporting 143091 errors, and it looks like they all have the same origin. Look at the central part of your unload code: ...
user avatar
  • 63.4k
1 vote
Accepted

PSET5: Segmentation fault in load function

Your problem is indeed in your load function. Think about what happens when you read the last letter of the first word in your dictionary. You get outside of the for loop iterating over its letters, ...
user avatar
  • 7,326
1 vote
Accepted

2014 pset5: Double free in load

I see a couple of problems here. First, in newword->next=malloc(LENGTH + 1);, 'newword->next' is a pointer to a node. You are allocating the space for newword->word, but not for the rest of the ...
user avatar
  • 63.4k
1 vote
Accepted

how to compile dictionary.c?

Try changing this else if (strcmp(&c, "'") == 0) into this else if (c == '\'') EDIT Try running make speller instead of make dictionary
user avatar
  • 7,326

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