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 ...
Micah Lindley's user avatar
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 ...
Cliff B's user avatar
  • 68.3k
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-...
DinoCoderSaurus's user avatar
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 ...
Blauelf's user avatar
  • 20.9k
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 ...
user9474943's user avatar
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 ...
Cliff B's user avatar
  • 68.3k
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 ...
Cliff B's user avatar
  • 68.3k
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 ...
curiouskiwi's user avatar
  • 18.6k
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 ...
Scott M Anderson's user avatar
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: ...
wenyi pan's user avatar
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 ...
DinoCoderSaurus's user avatar
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 ...
Cliff B's user avatar
  • 68.3k
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 ...
DinoCoderSaurus's user avatar
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 ...
Blauelf's user avatar
  • 20.9k
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 ...
Cliff B's user avatar
  • 68.3k

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