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 ...
Cliff B's user avatar
  • 68.3k
2 votes
Accepted

pset5 hashtable all words are mispelled, no memory leaking

What's that rogue unload(); doing at the end of your main loop in load?
Blauelf's user avatar
  • 20.9k
1 vote
Accepted

dictionary.c - pset5 segmentation fault

The first big problems I see are in check(). Look at this line: while(cursor->next != NULL) This is going to result in every other node being skipped, among other anomalies. It should be checking ...
Cliff B's user avatar
  • 68.3k
1 vote
Accepted

pset5/speller Check produces a segfault if I introduce hash function

The reason for the seg faults lies in check() It uses a do/while setup that checks whether temp is null after running the loop. If the bucket was empty and table[hashed] is NULL, then it's going to ...
Cliff B's user avatar
  • 68.3k
1 vote

Unknown memory leak on "check function" - CS50 Speller

Your code node *checker = malloc(sizeof(node)); /* ... */ checker = hashtable[index]; means you allocate a new node, and then you throw away the only reference to that node, leaving this ...
Blauelf's user avatar
  • 20.9k
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

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

PSET5 - dictionary works the same as staff solution, but fails check 50

Instead of a variable head, containing arbitrary value hashtable[0], use hashtable[hashed_number] (you might need to do the hashing a bit earlier)
Blauelf's user avatar
  • 20.9k
1 vote
Accepted

PSET5 Load: Memory allocation while passing / storing strings in Hash Function

I would take into consideration everything that ronga said! It's a bad idea to create such a massive array to serve as a giant buffer, when all that you need is one small buffer to hold only one word ...
Yuri Laguardia's user avatar
1 vote

pset5 load function help. what am i doing wrong?

Lots of syntax errors. while (!=EOF) The "not equal to" operator, !=, operates on two values or variables, comparing them. This statement has one value, EOF. The correct operator would be the not ...
Cliff B's user avatar
  • 68.3k
1 vote
Accepted

pset5-Hashfunction using the firste letter of the string

Let's assume that your question has several typos. It should read int hash = toupper(key[0])-'A'; Having said that, did you remember to add the two necessary includes for toupper()? #include <...
Cliff B's user avatar
  • 68.3k

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