13
votes
pset4 speller - can't pass valgrind test - 32 bytes still reachable
This appears to be a clang bug that we are investigating. Will update once we know more.
UPDATE
We have changed check50 and submit50 so the 32-byte "leak" no longer happens.
We will be updating ...
13
votes
Accepted
CS50 good hash function for PSET5 Speller
I'll take a run at explaining it. This is a very popular hash function for this pset and other uses.
It uses a seed value because changing the starting hash value, the seed value, has an effect on ...
6
votes
Accepted
How to know how many buckets for hash table - Speller PSET5
It depends. There are a lot of factors involved. Does the hash function have a limited number of possible values (like 26 if it's based on the first letter)? How much data are you processing? How ...
4
votes
pset4 speller - can't pass valgrind test - 32 bytes still reachable
Following the hint by @anastasy-korobetskaya, I have arrived at this workaround. Sadly, it only helps to get rid of the problem in the IDE, not upon submission, but at least it should allow you to ...
3
votes
Accepted
Speller 2019: dictionary could not be unloaded and the program identifies misspelled words wrongly
The errors give a very good clue to the problem. Program is "case sensitive" and must be "case insensitive". Perhaps investigate how you can use strcasecmp (as Zamyla mentions in the check walkthrough)...
3
votes
Accepted
pset5, load function. Initializing elements in hashtable to null
You can set each element individually to NULL using a for loop.
I see a small problem with it though. SIZE = 25, so that's elements 0 to 24. Interestingly, because of the way that the hash function ...
3
votes
Accepted
PSET 4 - Speller: Every single word is misspelled
Well, this was easy, if not hidden right out in the open. ;-)
Look at the core piece of the check code:
// Compare 2 strings
if (strcasecmp(cursor->word,word) == 0)
{
...
3
votes
Accepted
When declaring an array of pointers that will be a hash table, do you have to set all the elements of the array to NULL?
You should ALWAYS initialize pointers. Unless you're immediately allocating memory to them and setting them to a legitimate address, you should initialize them by setting them to NULL.
Note that if ...
2
votes
Accepted
how effective would it have been to use an array for the dictionary?
suppose we are to implement speller using an array instead of a hash-table or a trie.
a main problem that we have is that we don't know the number of words in the dictionary in advance (yes, we know ...
2
votes
Accepted
Declaring struct node and node array globally (hashtable implementation)
A global variable is one that can be used anywhere in the program. Generally, globals are considered to be a bad practice, but there are times where they are perfectly appropriate for the situation. ...
2
votes
how to check if just the load function is implemented correctly?
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 ...
2
votes
Accepted
how to check if just the load function is implemented correctly?
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 ...
2
votes
Accepted
How can I optimize load in pset5
You insert at the end of the linked list. Insertion is faster at the beginning. Instead of
nodeNew->next = NULL;
current = &hashTable[index];
/* iterate over nodes until reached ...
2
votes
PSET4 Speller(hashtable) cs50 2019 HELP!
This test in check if(temp->next != NULL) is the heart of the problem. What is the value of temp->next if there is only one word in the "position"? It is, of course, null. Realize that check50 ...
1
vote
Accepted
Pset5: Hashtable, cannot submit my code
The most likely reason for not qualifying is if your solution is too slow. If you compare your time running, say, ./speller texts/holmes.txt vs the staff solution ~cs50/pset4/speller texts/holmes.txt ...
1
vote
Accepted
pset5 load null pointer issue
char *word = NULL;
while (fscanf(dict, "%s", word) != EOF)
The problem lies with word. It's a pointer to NULL. Next, the fscanf does a read and stores it at NULL, the infinite bit bucket. In other ...
1
vote
Accepted
HashTable full of single value
You allocate space for one word. Then you copy its address to all your value pointers. Of course it's all the same word, as you re-use the same space all the time.
I used a char value[LENGTH + 1] ...
1
vote
Accepted
Two hash table questions
Hash tables are basically arrays of pointers, and the hash determines the index to use. Each of those pointers points to the first node of a linked list (or similar). A node of a linked list consists ...
1
vote
Accepted
Struggling with hash table! Pset5
new->word = dWord;
I'd say that the address of dWord is being copied into the pointer(s) new->word for every node created, and not the actual word. When every word is processed, it is written ...
1
vote
Accepted
Segmentation Fault on Hashtable
new->s="";
lets new->s point to an empty string stored in a read-only area.
strcpy(new->s,val);
then tries to write to that read-only area.
You need writable memory associated to the ...
1
vote
Accepted
Speller(hashtable) flagging all words as misspelled
First: You seem to have different spelling of wordcount/wordCount. Are you sure that's the code that you compiled and had valgrind on?
while (fscanf(fp, "%s", buffer) != EOF)
might better be
while (...
1
vote
Accepted
Segmentation fault occurs if I delete an unused global variable in Pset5
Looks like you're writing to some place you were not supposed to, overwriting your other variables on the stack.
Your hash function might not respect the range of 0-676 you specified. Input like the ...
1
vote
Accepted
Too many misspelled words - speller.c PSET-5
In check:
Always normalize (lowercase) your word before hashing, and hash the normalized version.
(This might be the reason for too many misspelled words)
Other, more random thoughts:
Your hash ...
1
vote
Pset5 - Problem with hash table load(), malloc, and segmentation-fault
What's causing your seg fault on this line is the sizeof operator:
newNode->word = malloc(sizeof(strlen(word) + 1));
What you really meant here was:
malloc((strlen(word) + 1) * sizeof(char));
1
vote
Accepted
Pset5 - Problem with hash table load(), malloc, and segmentation-fault
In check, you don't copy the terminator, you could add a tmpWord[wordLen] = 0; between the for- and the while loop.
It makes little to compare word and tmpWord (the lowercase version of word), but ...
1
vote
Accepted
Pset5 - dictionaries.c : My check output is very unrelated and confusing
The strcmp() function doesn't return a bool (true/false), it returns a number, depending on whether they are equal, or depending on which is "greater". If they are equal, strcmp returns 0. ...
1
vote
Accepted
My hash table works and has good running time but fails one check - :( handles max length (45-char) words
The max length of a word really is 45. But riddle me this: When you created/declared the buffer and set the size, did you set it to 45 (or set LENGTH = 45 and use LENGTH in the declatation)? Did ...
1
vote
Accepted
pset5 Load: Am I on the right track? Getting errors for pointer/integer confusion
The problem lies in the following:
alphabet[hash_value] = new_node;
The alphabet[] array is an array of integers. 'new_node' is a pointer to a node. This line of code is trying to stuff a memory ...
1
vote
pset5 speller: loads one more word
This line:
for(int i = 0; !feof(dict); i++)
The feof indicator will not be set until AFTER fscanf finds the end of file. So you will have to read past the end of file, store it (i have no idea how ...
1
vote
What's wrong with my load function? for cs50, pset5. Im sure all other functions are correct
There are a few things that your load function should be doing:
Just as with a dictionary, you want everything to be arranged alphabetically. That means you should have first created an array of 26 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
hash-table × 85pset5 × 50
speller × 44
pset4 × 15
load × 13
linked-list × 10
pset6 × 7
hash-function × 7
cs50x × 5
c × 5
segmentation-fault × 5
dictionary × 5
pointers × 4
speller-check × 4
check × 3
trie × 3
array × 3
malloc × 3
hash × 3
pset5-hashfunction × 3
valgrind × 2
cs50x2019 × 2
pset4-speller × 2
unload × 1
binary-search × 1