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 ...
  • 66.6k
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?
  • 20.8k
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 ...
  • 66.6k
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 ...
  • 66.6k
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 ...
  • 20.8k
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 ...
  • 66.6k
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 ...
  • 18.5k
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)
  • 20.8k
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 ...
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 ...
  • 66.6k
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 <...
  • 66.6k

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