1
vote
PSET 5 Hash help
You've got a few different problems. First, take a look at your first call to fopen(). You call it again to check if the result is NULL, but that's incorrect. Instead, try declaring a variable with ...
1
vote
PSET 5 Hash help
Let's talk about how you're using the hash function first. Here's your code:
hash(word)
Ignoring the missing semicolon, this is a normal function call. Since hash() returns an int, the code ...
1
vote
Speller Valgrind leaks bytes + error: munmap_chunk(): invalid pointer error in C
This program does not compile in the IDE (or check50). First error in IDE:
dictionary.c:28:13: error: implicit declaration of function 'hash' is invalid in C99
[-Werror,-Wimplicit-function-...
1
vote
PSET4 free on malloc in hash function
str++ will increment str. So the thing you later try to free is pointing to the first byte behind the string's null terminator, while you are meant to call free for the first byte of the range, the ...
1
vote
Accepted
PSET5: Hash function returning collisions
There are better options than the DJB2 algorithm! Try using this algorithm called Murmur2! From what I've gathered, it's great in terms of speed and excellent in distribution!
Here's a StackExchange ...
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
Check function too slow in pset5
There are any number of hash functions available on the internet. You just have to pick one.
As far as controlling the number of buckets, that's easy. Just modulo with the number of buckets. For ...
1
vote
Accepted
Pset 5 Speller - Undefined reference to hashValue in load and check
inline int hashValue(const char* word)
Not sure why you have inline there, but remove that and it should compile fine.
Secondly, looks like you changed the declaration of check. It needs to be
...
1
vote
Accepted
16 letter words show up as misspelled from Pset5
I do not know why exactly this was an issue(only 16 letter words?), but the problem was in Check(). My variable for copying the constant char was set up as:
char editword[strlen(word)];
it should ...
1
vote
16 letter words show up as misspelled from Pset5
I'm getting this same bug even though I used a different hash function. not sure what this problem is. The rest of my program works perfectly.
Here's my hash function:
// Source of hash function: ...
1
vote
Accepted
Pset5 speller - load clang error (linker command error) and multiple definition
True, the function is defined once in dictionary.h. However, the compiler sees that definition twice, the first time when it encounters #include "dictionary.h" in speller (notice the reference to ...
1
vote
Accepted
Is this hash function valid?
Almost got it. What happens if the first letter (common in the text being checked) is upper case?
If this answers your question, please click on the check mark to accept. Let's keep up on forum ...
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
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
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
hash-function × 25pset5 × 21
speller × 17
hash-table × 7
load × 5
pset5-hashfunction × 4
cs50x × 2
c × 2
dictionary × 2
pointers × 2
malloc × 2
hash × 2
pset4 × 1
pset6 × 1
segmentation-fault × 1
valgrind × 1
check × 1
trie × 1
memory-leak × 1
segfault × 1
clang × 1
cs50x2020 × 1
speller-check × 1