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, ...
3
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 ...
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'...
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 ...
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 ...
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 ...
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 ...
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.
...
2
votes
Accepted
Finance index function does not return lookup value in index.html
Each dict in portfolio contains 3 keys as returned from the execute. There is no key current_price, so the html does not render anything for that column. If the key gets created in the for loop in ...
1
vote
Pset 5 speller trie check function - check50 handles everything but possessives and substrings
Your node should have some property telling whether it encodes a word, or is just the beginning of one, like the trav->children[c]->is_word you mentioned in the comment.
I don't think it's a ...
1
vote
Accepted
Why does this hash function fail?
I assume you have created str2 for the case insensitivity. No memory has been allocated to it, therefore anytime you write to it (as with strcpy), there will be an "invalid write". (And if you ...
1
vote
Accepted
Pset5 - Could not open dictionary
I don't think that this is a code problem, but is a file name problem. I believe the dictionary name is small, not small.txt.
If this answers your question, please click on the check mark to accept. ...
1
vote
Accepted
PSET 5 Words not loading in memory
I'm highly suspicious of the following two lines:
char* temp = NULL;
while (fscanf(dict, "%s", temp) == 1)
The temp var is a pointer set to NULL, which you then try to read a string into. No memory ...
1
vote
Accepted
PLEASE HELP How to contemplate the last line in dictionary (the empty one)
Instead of your current while loop, try
while fscanf(etc...)!=EOF
//malloc new node, etc.
1
vote
Accepted
PSET 5: Dictionary.c, Trie structure, Check/Load, All words misspelled
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[...
1
vote
Accepted
Cannot load dictionary
If you're getting the "cannot load dictionaries/large" error, it sounds like it isn't a coding problem, it's a file location problem. For the default dictionary to load, it has to be named large, and ...
1
vote
Accepted
Unknown problem with dictionary.c Help!
you are trying to compile dictionary, at this point should know that you can not compile a program that does not have main () function instead must compile speller.c, plus you have in pset5 directory ...
1
vote
PSET5 Question about pointers
Regarding const
Exact reason you're putting const there is to notify
1) the compiler that you have no intentions to modify that variable. Allowing it to optimize or throw an error just in case you ...
1
vote
Accepted
Problems with hash function in pset5
The code will return index % HASHSIZE;, but where is index calculated? Maybe index was supposed to be hash?
If this answers your question, please click on the check mark to accept. Let's keep up on ...
1
vote
Kinda confused with what needs memory allocated in pset5
well, no where to start, first see the hash tablenode* hashtable[ALPHA], is an array of pointers to node, are pointers we will use to store our words according to their index hash, to equal hash index ...
1
vote
Accepted
Implementing a trie. Updated load function in dictionary.c causes more problems with valgrind
I'm trying to figure out the best way to tell you this so that you can find it on your own, without just telling you where the problems lie. The good news is that the total memory leak code fix is ...
1
vote
pset5 Misspellings - passes check50 - doesn't work with larger text file
My suspicions were correct. The problem lies in load(), not check(). It is a very subtle logic problem.
If you were to write a function to traverse your dictionary after load finished, you would find ...
1
vote
Accepted
Pset5 600 out 644 words misspelled. What am I missing?
There are two major problems with the code. First, neither load nor check are coded to handle apostrophes. Because of that, the value of index will be set at the ascii value of an apostrophe every ...
1
vote
Speller is not giving expected out
Both load and check have problems.
In load, trav is not reset to point at root after adding a word to the dictionary, so the only actual word in the trie is the first word from the dictionary.
...
1
vote
Accepted
My program "works" just fine but it won't pass check50?
"Ready, Fire, Aim!" You indeed do have an off-by-one error because of the way you handle the end of file condition while processing the dictionary.
Look at your while loop construction. The ...
1
vote
Accepted
Pset5, load skips first letters and the last word; Dictionary isn't loaded
point->children[tolower(ch) - 'a'] = malloc(sizeof(node));
point->is_word = false;
When you set is_word to false, point is still pointing at the "letter" before in the trie, so you are then ...
1
vote
Pset5, load skips first letters and the last word; Dictionary isn't loaded
I see a couple of conspicuous issues. First, the code increments wordcount for every character read in, not every word. That's going to throw your word count way off.
Second, when you malloc new ...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
dictionary × 152pset5 × 106
speller × 95
load × 34
trie × 16
valgrind × 15
check × 14
pset6 × 9
cs50x × 9
segmentation-fault × 7
unload × 6
check50 × 5
python × 5
hash-table × 5
dna × 5
misspelling × 5
memory × 4
free × 4
c × 3
pointers × 3
malloc × 3
lookup × 3
finance × 2
appliance × 2
error × 2