Hot answers tagged

10 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 ...
  • 64.6k
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 ...
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[(...
  • 64.6k
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 ...
  • 64.6k
2 votes
Accepted

Check function skipping the check and returning all words as misspelled

print thisNode->word $2 = "elephant\n" Looks like you are including the new line char in your word. This will cause all of the words to be misspelled, as the word sent to check will, of course, ...
  • 18.4k
2 votes
Accepted

pset5 speller, check function returns all words as false

The second version looks cleaner so let's go with that. Without seeing the rest of the check function, or the load function, I think I still found your problem. Assuming that pointer->children[] is a ...
  • 64.6k
2 votes
Accepted

Comparing jpg-signatures with fread-buffer; Can't find something

buffer is an array of ints. on the appliance, an int is 4 bytes long. this means that the total size of your array is 512 * 4 = 2048 bytes not 512 (which you want) but that's not the actual problem. ...
  • 17.4k
2 votes
Accepted

Return value of load()

The hash table that you've loaded the words into should be globally accessible since many functions will use it and a direct access would make things way easier. Also, you're not supposed to alter ...
  • 17.4k
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 ...
  • 64.6k
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]; ...
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 ...
  • 64.6k
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 ...
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 ...
  • 64.6k
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 ...
  • 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 ...
  • 3,036
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() ...
  • 3,036
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 ...
  • 18.4k
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 ...
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. ...
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 ...
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 ...
  • 64.6k
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.
  • 20.7k
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()"...
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 ...
  • 64.6k
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 ...
  • 64.6k
1 vote
Accepted

Why does check find so many misspellings?

I suspect that you have more than one problem in your code, but can't be sure without seeing all of it. However, I think I located one significant issue. Look at the code near the end of your load ...
  • 64.6k
1 vote

pset 5 Recover check if file open

Supposing that before the loop you declare the file where you will write data FILE *jpgfile = NULL; You can use if (jpgfile != NULL) to check if you have an already open file.
  • 157
1 vote

Infinite loop in speller.c check function

while (cursor is not NULL) //here is where the infinite loop begins { if( cursor->word = new_node->word) //this is using strcmp { return true make cursor = cursor->next; } } ...
  • 17.4k
1 vote
Accepted

Why doesn't my program handle sub-strings properly?

Why are you checking the first node on line 71 separately? Also what if the linked-list that you're searching into consists of x nodes and the word is the last node? Following the logic of your code,...
  • 17.4k
1 vote

losing node in the span of a few lines

It looks like you have implemented a trie for your dictionary and you are trying to traverse the dictionary letter by letter to see if a word exists. In this code block... if(current_Node-> ...
  • 64.6k

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