2 votes
Accepted

Check function (pset5, speller) gives multiple, incorrect outputs for some reason

There are a few problems here. First, there is a logic issue in adding nodes to the tree: else { n->next = head; table[index] = n; } This works ...
  • 66.7k
2 votes
Accepted

pset5 speller Invalid write of size 1

Did you know that sizeof(word) returns the length of the word variable? That's right, 8 bytes on a 64-bit system. The variable stores a memory address of the first byte of the string (stored somewhere ...
  • 20.8k
2 votes
Accepted

Pset5: strcasecmp doesn't return 0 when given the same string input

Perhaps there's a slight oversight in your code. Look at the following: lc_word[len + 1] = '\0'; Now, say that the word is "Cat". Length is 3 so len = 3. Remember that arrays start at 0,...
  • 66.7k
2 votes
Accepted

Speller beyond my reach: all words marked as misspelled

The problem with the misspelled words lies in check, specifically with this: while (cursor->next != NULL) // wonder if this should be while (cursor != NULL) ? Your wondering is exactly on target. ;...
  • 66.7k
2 votes
Accepted

Can anyone see what is wrong with my check function?

Actually, the problem lies in load. free(n); This is corrupting the dictionary tree. Remember, n is a pointer to memory. When you free it, you free that memory. Even if it has been added to the ...
  • 66.7k
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.7k
1 vote
Accepted

PSET5 Speller - Problem with Check Function

The most obvious problem is the use of the pointer headPointer. The code updates this pointer to point at the new node just added. The problem with that is that table[] will never get updated, so the ...
  • 66.7k
1 vote
Accepted

Speller pset 5 my code is not working for substrings

Actually, it's not working with a lot more than that. Since check50 is using very small test data lots, it's actually not seeing the underlying problem in other tests. This is a good lesson in why ...
  • 66.7k
1 vote
Accepted

Speller skips last word in testfile I use

speller.c is responsible for sending the words to your check function. So it's not your code. Notice that speller only recognizes a word if it ends in punctuation or whitespace. Your test text's ...
  • 18.5k
1 vote
Accepted

pset5 speller check50 error - code doens`t handle max length (45char)

After several false starts, we finally got the code to test. Have you tested your code with a 45 char word in a dictionary? The code is generating a seg fault when the dictionary is composed of ...
  • 66.7k
1 vote
Accepted

Speller.c doesn't work

Although you're doing a case-insensitive comparison between the word to be checked and the dictionary words, the code is hashing the word with capital letters. That means that any word with a capital ...
  • 66.7k
1 vote

I am working since past 4days on pset5 (speller) .All the words of dictionary are shown as mispelled. Please help me out. Thank You

fscanf(file , "%s" , word) By design, fscanf automatically put '\0' in the end. So if it reads cat\n, the result is cat\0. By doing this: word[strlen(word) - 1] ='\0' you overwrite the last char ...
  • 1,139
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

Speller (hashtable) check-function marks everything as correct

I took a very quick glance at it and see this: if (strcmp(word, wordcheck->word)) { return true; } This tells me that you've assumed that strcmp returns true/...
  • 66.7k
1 vote
Accepted

do not understand why check function checks new word against dictionary

No, not at all. You're conflating two different var names to be the same variable. Let's look at the code: // Returns true if word is in dictionary else false bool check(const char *word) { ... if ...
  • 66.7k
1 vote
Accepted

Pset4 speller segmentation fault in check functions when using larger files like holmes.txt

You're on the right track. The problem is definitely within the hash function. I added a printf statement to print every word being checked to find out which word was triggering the seg fault. The ...
  • 66.7k
1 vote
Accepted

Pset 4: Speller (trie) - misspelled words

Hmmm, interesting problem. ;-) I made a few assumptions on declarations, but they appear to be right. So, let's look at the core block of code that inserts the word into the trie. for (int i = ...
  • 66.7k
1 vote
Accepted

Problem with the check function in pset5

sizeof(word) sounds like what you want (here for (int i = 0; i < sizeof(word); i++) {, but it is not. sizeof returns how many bytes the argument uses in memory. Iin this case word is a pointer, and ...
1 vote

PSET 5 Spell Checker - Error: Could not load dictionaries/large

Ugh! I figured it out. I was returning "false" from the load function. Can't believe I missed that! Resolved.
1 vote
Accepted

pset5 check - stuck in loop

check should not allocate any node (just set your traversal pointer to hashtable[hash_value]) Your problem is likely in the load function, where you allocate your nodes and place them in the hash ...
  • 20.8k

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