Hot answers tagged

11 votes
Accepted

Speller.c appears to be working but is case sensitive (can't recognize capitol letters)

It's something you overlooked. Your hash function determines the hash value by adding the ASCII values of every letter in the word. The problem is that an upper case letter won't produce the same ...
Cliff B's user avatar
  • 68.3k
4 votes
Accepted

How to make the check function faster?

The reason why your check function is slow is because of how the dictionary is loaded into memory. There are two things to do to right this: 1.) Find a good hash function online like this one I found ...
NullityNull's user avatar
3 votes
Accepted

expected expression pset5 dictionary.c if-else

The problem is bad structuring of the chain of ifs and else ifs. Look at the following: if(...) { ... } else if (isupper((char)*(word + i))) { else if (cursor -> children[(...
Cliff B's user avatar
  • 68.3k
3 votes
Accepted

PSET5 Speller, faster check and load times hashmap

This is an ineffective use of a hash function. In essence, your load function simply inserts each word sequentially into an array, along with a hash number, and the check function is doing a linear ...
Cliff B's user avatar
  • 68.3k
2 votes

pset5 trie check segmentation fault

OK, after careful debugging I have discovered and fixed the issue. It doesn't have to do with malloc/calloc. Even though my forward declaration of the struct/root node was properly placed outside of ...
Avishai Fuss 's user avatar
2 votes
Accepted

Can't free malloc used in check

Well, it seems to me that if you want to free that particular malloc, you need to have two free() statements, one immediately before each return so that no matter how you exit, it gets freed. For the ...
Cliff B's user avatar
  • 68.3k
2 votes
Accepted

Problems with letters "a" and "I" misspellings

TL; DR: This looks like a memory leak. Remove: node *tableindex = malloc(sizeof(node)); tableindex = hashtable[ind]; ... free(tableindex); Add: node *tableindex = hashtable[ind]; ...
Sam Gerber's user avatar
2 votes
Accepted

pset5 - possessives and substrings

Actually, your problem is a lot more severe than it appears. You are getting a massive number of false positives. I say that they're false because you're not actually checking the words correctly. So ...
Cliff B's user avatar
  • 68.3k
2 votes
Accepted

Load and Check error in pset5

Simply put, the while loop in check() never starts. Look at the following code: unsigned int c =0; unsigned int i = 0; while(c != '\0') int 0 is the same as \0 in their binary ...
Cliff B's user avatar
  • 68.3k
2 votes

pset5 Check Function (trie version) giving a segmentation error

I just figured out the answer (in case anyone has a similar issue). And actually the error was in Load so apologies for not including that (I didn't want to paste too much of the pset in). I declared ...
jamiej's user avatar
  • 21
2 votes

PSET5 Speller, faster check and load times hashmap

As usual, Cliff B has explained things very well in his answer. I'd just like to add a more succinct explanation. Your problem is that you want to keep the dictionary sorted alphabetically and also ...
hotwebmatter's user avatar
  • 3,050
2 votes
Accepted

PSET5 : Question about structs

When you declare node* you are not declaring a variable of type struct node. Rather, you are declaring a pointer-to-node. A pointer is just a memory address. This is why, when you check the sizeof() ...
hotwebmatter's user avatar
  • 3,050
2 votes
Accepted

Pset 5 - Question on check(), diff, and check50 (and I found it interesting)

The second one is incorrect and it only passes check50 because of the very small dictionaries that check50 uses. In your original version, you create a pointer that points to the hashtable, and you ...
curiouskiwi's user avatar
  • 18.6k
2 votes
Accepted

CS50 PSET5 Won't Work With Apostrophes

You have: else if (l == '\'' && trav->children[26] == NULL) { trav->children[26] = calloc(1, sizeof(node)); } So, what if you do have an apostrophe but trav->children[26] is not ...
Ricardo David Antonetti's user avatar
2 votes
Accepted

PSET5 Speller / Dictionary - Seg Fault and Incorrect Check

You can jump to SUGGESTION for quick answer. I plugged your check() function on my dictionary.c program. I also have a trie in my dictionary.c. I don't know what is causing the segmentation fault. ...
Ricardo David Antonetti's user avatar
2 votes
Accepted

pset5 check function and const char* word

Can't tell you exactly what's happening without seeing your entire code, but one thing I can tell you right away is that you're forgetting to allocate space for the null terminator when you only ...
Yuri Laguardia's user avatar
2 votes
Accepted

PSET5 - Trie Check Segmentation Fault

It's a common problem. The problem lies in load(), where you have created a "shadow variable." A shadow variable happens this way: First, the original variable is created, either earlier in main or a ...
Cliff B's user avatar
  • 68.3k
2 votes
Accepted

pset8 - finance - check - ajax - preventDefault()

You have to stop the submission now (in the submit event listener), and in case of success submit in the AJAX callback. Submitting via JavaScript will not trigger another submit event.
Blauelf's user avatar
  • 20.9k
2 votes
Accepted

PSET 8: Finance /check

So, as it turns out - the error was in the Python code. I used "request.form.get()" when I should have used "request.args.get()" since its a GET request not a POST request. Using "request.args.get()"...
Adam DeCaria's user avatar
1 vote
Accepted

In Check50 I get a Segmentation Fault, and trying myself gives me an endless loop

I don't understand why you are getting to check, or appear to be getting an infinite loop. When I ran your posted code, it immediately generated a seg fault. The problem is exposed here: for (int c =...
Cliff B's user avatar
  • 68.3k
1 vote
Accepted

CS50 dictionary.c problem with hashtable

Without seeing the load and hash functions, it's almost impossible to know what's wrong. It could be that the hash function isn't giving the same result for the same word each time, or the word that ...
Cliff B's user avatar
  • 68.3k
1 vote
Accepted

pset5: problem with check function

Having seen your load function, I don't think it's working correctly. If you get a word that hashes to the same value as a previous word, the code will drop into the else clause and will try to place ...
Cliff B's user avatar
  • 68.3k
1 vote
Accepted

Pset5 600 out 644 words misspelled. What am I missing?

There are two major problems with the code. First, neither load nor check are coded to handle apostrophes. Because of that, the value of index will be set at the ascii value of an apostrophe every ...
Cliff B's user avatar
  • 68.3k
1 vote
Accepted

Pset5 - dictionaries.c : My check output is very unrelated and confusing

The strcmp() function doesn't return a bool (true/false), it returns a number, depending on whether they are equal, or depending on which is "greater". If they are equal, strcmp returns 0. ...
Cliff B's user avatar
  • 68.3k
1 vote

Speller is not giving expected out

Both load and check have problems. In load, trav is not reset to point at root after adding a word to the dictionary, so the only actual word in the trie is the first word from the dictionary. ...
Cliff B's user avatar
  • 68.3k
1 vote

Trie is failing in Check function

Your problem lies in what's not in the code - two oversights. The code doesn't actually check is_word when it actually gets to the end of a word in the trie. Say that your dictionary had the words ...
Cliff B's user avatar
  • 68.3k
1 vote

pset5 all words misspelled

Is the phrase "Start load" being printed out when you run the program? If not, that should tell you something big.
Cliff B's user avatar
  • 68.3k
1 vote

Pset5: speller.c listing all checked words as misspelled

Didn't really look into the code because there's a major problem right at the beginning of check(). Look at the following: bool check(const char* word) { root = malloc(sizeof(node)); As soon as ...
Cliff B's user avatar
  • 68.3k
1 vote
Accepted

PSET 6, Issue checking misspelled words

130// points to the old head new_node = hashtable[index]; // this new node will be the head hashtable[index] = new_node; I think this code in your gist will keep reassigning new nodes at each ...
johnnyd3's user avatar
1 vote
Accepted

Pset5 - Apostrophe and check problems with Tries

There are several problems. The most significant is this: for (char* i = buffer; *i != '\n'; i++) { // creating a variable to store letters in int templetter = i[j]; This code is supposed to ...
Cliff B's user avatar
  • 68.3k

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