0

I don't really get why even though I handle the apostrophe case I think correctly

here is what check50 gives me

:) dictionary.c, dictionary.h, Makefile exist
:) speller compiles
:) handles most basic words properly
:) handles min length (1-char) words
:) handles max length (45-char) words
:) spell-checking is case-insensitive
:( handles possessives properly
   \ expected output, but not "\nMISSPELLED WORDS\n\n\nWORDS MISSPELLE..."
:( handles substrings properly
   \ expected output, but not "\nMISSPELLED WORDS\n\ncats\n\nWORDS MIS..."
https://sandbox.cs50.net/checks/135394fd9f264f9fa20d8571628b4001

and here is my check function

bool check(const char *word)
{

    // creat arrow to follow letters
    NODE* arrow = root;

    // for every letter in word
    for (int i = 0, length = strlen(word); i < length; i++)
    {
        int index;

        // indexing letters
        if(isalpha(word[i]))
            {
                 index = tolower(word[i]) - ASCII_DIFFERENCE;

              // indexing apostrophe  
            } else
            {
                index = 26;
            }


        if (arrow->child[index] == NULL) // if NULL? not in dict
        {
            return false;
        } else if (arrow->isWord)  // word exists?
        {
            return true;
        } else // other wise move arrow to child
        {
            arrow = arrow->child[index];
        }
    }


return true;

}

any helps or tips is much appreciated

EDIT:

I watch the Walkthrough again and followed the pseudocode step by step and here is my function

bool check(const char *word)
{



    // creat arrow to follow letters
    NODE* arrow = root;

    // for every letter in word
    for (int i = 0, length = strlen(word); i < length; i++)
    {
        int index;

        if(word[i] == '\'')
            {
                index = 26;
            } else
            {
                index = tolower(word[i]) - ASCII_DIFFERENCE;
            }


        if (arrow->child[index] == NULL) // if NULL? creat a new one and move arrow to new child
        {
            return false;
        } else if (arrow->child[index] != NULL)  // not null?
        {
            arrow = arrow->child[index];
        } 
    }




return arrow->isWord;


} 

after check50 the substrings error has been fixed but the possessives error is still there

:) dictionary.c, dictionary.h, Makefile exist
:) speller compiles
:) handles most basic words properly
:) handles min length (1-char) words
:) handles max length (45-char) words
:) spell-checking is case-insensitive
:( handles possessives properly
   \ expected output, but not "\nMISSPELLED WORDS\n\nfoo's\n\nWORDS MI..."
:) handles substrings properly
https://sandbox.cs50.net/checks/40efd0e8488444cba28963e79406837c
1

The check50 is saying that possessives aren't being handled properly, but that could be in "load" or "check".

Possessive's are handled in the "load" function too. You seem to only be sharing the "check" function, but the possessive's are put into the trie in the first instance in the "load" function, so you may want to take a look at your code there.

2
  • I just figured it out that I didn't load the apostrophes into my trie tree, thanks a lot, and as usual a stupid mistake :(((( – Yasser Altamimi Mar 11 '17 at 23:34
  • Great, glad to have helped! – Rachel Mar 11 '17 at 23:36
1

It is possible both failures have the same cause. What does the program do if it "runs out of word" before it "runs out of trie nodes"? *

You can construct a small test taking a hint from the expanded information in the sandbox link. Try with a dictionary of one word foo's and a text of one word foo. speller will report no misspelled words.


* hover below for the answer.

Control goes here return true; and the word is spelled correctly.

2
  • I didn't get what you mean by "What does the program do if it "runs out of word" before it "runs out of trie nodes"? *" also return true at the end I don't get the reason why compiler is not happy when I remove it as I covered all possible cases (I guess) with my if else statements, can you please explain more, thanks a lot – Yasser Altamimi Mar 11 '17 at 21:57
  • I edited my code and my post if you please can check that, I really appreciate it @DinoCoderSaurus – Yasser Altamimi Mar 11 '17 at 22:31

You must log in to answer this question.

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