Skip to main content
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 ...
curiouskiwi's user avatar
  • 18.7k
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
  • 69.1k
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 ...
Cliff B's user avatar
  • 69.1k
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 ...
Martino's user avatar
  • 51
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) { ...
Cliff B's user avatar
  • 69.1k
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)...
DinoCoderSaurus's user avatar
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 ...
Cliff B's user avatar
  • 69.1k
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 ...
Cliff B's user avatar
  • 69.1k
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 ...
Blauelf's user avatar
  • 21k
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 ...
kzidane's user avatar
  • 17.7k
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 ...
DinoCoderSaurus's user avatar
1 vote
Accepted

CS50 [Speller_hashtable] my hashtable is weird!

The code doesn't actually stop after MISSPELLED WORDS. It is actually going into an infinite loop. The line while (cursor != NULL) is looking for a NULL pointer value. Unfortunately, the nodes are ...
Cliff B's user avatar
  • 69.1k
1 vote
Accepted

PSET4 (Speller) malloc and calloc usage

When you copy over the word into your node, you forget to write a null terminator. The byte likely is initially zero, so your programme will probably work, but there's no guarantee. Using calloc ...
Blauelf's user avatar
  • 21k
1 vote
Accepted

Speller (hash) memory leak?

Move the return true; out of your for loop in unload. You unload all the words starting with "a", but no other words, since you return from the function early. Unrelated, your unload has a free(...
Blauelf's user avatar
  • 21k
1 vote
Accepted

I can't figure out what's wrong with my speller (hash) code

Remove the first fscanf. With two of them, you read two words, and discard the first. You could even get rid of the break; if you put it into the loop condition. Having a stack variable temporary ...
Blauelf's user avatar
  • 21k
1 vote

Speller(hashtable) VALGRIND ERRORS!

free(temp); in check is wrong, in both instances. But luckily it is dead code, never executed, because you return earlier. In unload, you should not malloc, this memory is lost on re-assigning to the ...
Blauelf's user avatar
  • 21k
1 vote

pset4 speller - can't pass valgrind test - 32 bytes still reachable

I'm having the same problem, working on a speller with a trie. Just spent a few hours chasing it, and managed to isolate the issue by doing the following: Unzipping a new set of files for pset4 (to a ...
Martino's user avatar
  • 51
1 vote
Accepted

PSET5 "Linker Command Failed with Exit Code 1"

Are you trying to make dictionary or make speller? You can't make dictionary because it's not a complete program. Yet, you say that it will compile. It makes me wonder if it compiles locally, but ...
Cliff B's user avatar
  • 69.1k
1 vote

pset4 speller all words are misspelled

Interesting. I ran a test using a small dictionary and noted immediately that the only words that were coming back as correct were the ones pointed to by the pointers in hashtable. Anything that wasn'...
Cliff B's user avatar
  • 69.1k
1 vote
Accepted

CS50 - Speller (Hashtable) - Misspelled all words

head is a local variable, initialised to a copy of variable hashtable[i]. When you re-assign it, you don't automatically change hashtable[i]. Assign to the hashtable entry instead.
Blauelf's user avatar
  • 21k
1 vote
Accepted

pset4 Speller hash table basics

Without seeing exactly what the new code looks like (certain important aspects may be missing from your description), it's still pretty obvious what happened. In the pointer implementation, a new ...
Cliff B's user avatar
  • 69.1k
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 ...
curiouskiwi's user avatar
  • 18.7k
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
  • 69.1k
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] ...
Blauelf's user avatar
  • 21k
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 ...
Blauelf's user avatar
  • 21k
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 ...
Cliff B's user avatar
  • 69.1k
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 ...
Blauelf's user avatar
  • 21k
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 (...
Blauelf's user avatar
  • 21k
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
  • 21k
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 ...
Blauelf's user avatar
  • 21k

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