1

I really need your help i have been banging my head almost 4 days now, check50 doesnt want to cooperate with me. whenever i run speller.c it loads the dictionary but it doesnt handle the words in substrings and possessives i have no idea why. These are the results of the check50, valgrind shows no errors or memory leaks but it doesn't print the misspelled words

:) 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\n\nWORDS MISSPELLE..."

Here is my check code

  bool check(const char* word)
  {
      node* nod = root;
      for (int i = 0, n = strlen(word); i < n; i++)
      {
           if (isalpha(word[i]) && word[i] == '\'')
           {
               int index = tolower(word[i]) - 'a';

               if (word[i] == '\'')
               {
                   index = 26;
               }
               if (nod -> children[index] == NULL)
               {
                   return false;
               }
               else 
               {
                   nod = nod -> children[index];
               }
           }
      }    
      if (nod -> is_word == true)
      {
            return true;
      }
      return false;
  }

1 Answer 1

2

I think in this condition you mean OR instead of AND:

if (isalpha(word[i]) && word[i] == '\'')
{

This condition will never be true. No character can be alphabetical AND an apostrophe at the same time.

You might want to change that to:

if (isalpha(word[i]) || word[i] == '\'')
{

You must log in to answer this question.

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