0

I am having issues with this problem set. I have already implemented the load and size function. I am having issues with the check() function.

This is the output I get when I run ./speller texts/austinpowers.txt vs the output of cs50's staff

left is my output, right is theirs

WORDS MISSPELLED: 17822 vs 644 (check not working)

WORDS IN DICTIONARY: 143091 vs 143091 (load seems to work)

WORDS IN TEXT: 19190 vs 19190

TIME IN load: 0.04 vs 0.04

TIME IN check: 0.01 vs 0.02

TIME IN size: 0.00 vs 0.00

TIME IN unload: 0.00 vs 0.01

TIME IN TOTAL: 0.05 vs 0.07 * I haven't coded the unload() yet, that's the reason mine seems faster, and also the check function isn't working which is maybe skipping a lot of operations.

I know there are a lot of wrong things about my code related to design and memory which I'll fix after it is functioning correctly with some design tweaking and valgrind

this is my check function: https://gist.github.com/anonymous/a638f4a10bd5f1e50f3d

this is the all the code: https://gist.github.com/anonymous/5f7ec3c7d551d56b3afb

I have a few thougts, my issue could be:

the '\0' character, the '\n' character (maybe in the load() which as a side effects breaks my check()?. I've been trying to overwrite '\n' with '\0' in index strlen(word) but to no avail the output of my program remains the same

*note that I am using the format %s\n in scanf in load()

It could also be the node* cursor; because cursor -> doesn't really exist, but I am using it because cursor points to the head called hashtable[hash(word)] and therefore if cursor points there cursor -> next will point to the head which points to the first element which does have a ->next if not NULL

thanks

2
  • also when I said I tried overwriting \n with \0 I know it's a const char, so when I try I write a temporary variable, I copy the whole string from word to such temporary variable and then overwrite that (and also use that for comparison)
    – Rafael
    Commented Mar 13, 2016 at 18:47
  • also the condition in the while loop ( check() ) has comment slashes before != NULL, when I remove those slashes then misspelled words become equal to total words in text. I am now realizing that the node* cursor thing may be okay, it may have to do with the \0 and \n characters making all comparisons fail, but I've tried everything I possibly could with \0 and \n :(
    – Rafael
    Commented Mar 13, 2016 at 18:51

1 Answer 1

1

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 index to point to the first node that was inserted.

For example, if the first word inserted at index 0 is "cap", and then you insert "cat" at index 0 your load function will set the "cat" new_node pointer to the, already stored, node pointer to "cap" at line 131 above. And so on.

Therefore each element in your hashtable array will only have the first node to be inserted at that index, rather than the entire linked list.

I'm guessing what you want is:

new_node->next = hashtable[index];

This would also explain why your dictionary.c catches some correct spellings but not most of them, and why your check function exits very quickly.

12
  • Thank you! now it's getting 675 misspells instead of 644 which is much closer. However, I am getting kind of a weird output this is mine gist.github.com/anonymous/1c1a7b19fd197eb0095a and this is theirs gist.github.com/anonymous/f4c22fe38f28ecc98e69 which is weird because I am getting some words but all the others misspellings just the character 'a' o.o
    – Rafael
    Commented Mar 13, 2016 at 19:57
  • Hey Can you elaborate or post a screenshot? I'm sure you know this already, but: I found it really helped to make small dictionaries and small texts for debugging this pset.
    – johnnyd3
    Commented Mar 13, 2016 at 20:01
  • Sure, I'll try with smaller dictionaries and text and I'll post an screenshot or even a video in a few minutes
    – Rafael
    Commented Mar 13, 2016 at 20:05
  • I am doing this now: I set the TABLESIZE to 1 and the hash function to always return 1 (for debugging purposes) and I took these pictures: imgur.com/a/r8YJC
    – Rafael
    Commented Mar 13, 2016 at 20:15
  • As you can see from the pictures, I got a fragment of text from alice.txt and made a dictionary with a few words and pasted the same fragment in the text so that it will all be correct. However, I added some words that aren't in the dictionary, so that the spellchecker marks those as misspelled. It should output 26 words, not 29. Number of words in dictionary is right. and got 12 out of 16 misspelled words which are: words with numbers, and all caps words. I don't really know why it got Poor.
    – Rafael
    Commented Mar 13, 2016 at 20:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .