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 ...
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[(...
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 ...
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
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 ...
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 ...
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 ...
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 ...
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 ...
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() ...
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 ...
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 ...
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.
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
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 =...
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 ...
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 ...
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 ...
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. ...
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.
...
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 ...
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.
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 ...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
check × 189pset5 × 121
speller × 76
load × 57
trie × 23
segmentation-fault × 14
dictionary × 14
pset6 × 13
check50 × 13
finance × 13
pset8 × 9
pset1 × 6
cs50x × 6
pset4 × 5
valgrind × 5
pset3 × 4
recover × 4
c × 4
error × 4
unload × 4
hash-table × 3
fails-check50-but-works × 3
memory-leak × 3
loop × 3
gdb × 3