0

I've been having some difficulties with the check function. It seems to work when all the words in my text file are lowercase but any capital letters are returned as misspelled.

I iterate through through both the dictionary and text characters and use the tolower function. My program also doesn't return the last word in a text file if it is misspelled. Can you give me any help? *Updated

 bool check(const char* word)
 {
       char word2[strlen(word) + 1];
       strcpy(word2, word);
       int check = 0;

       for(int i = 0; word2[i] != '\0'; i++)
         {
        if(isalpha(word2[i]))
        {
            word2[i] = tolower(word2[i]);
        }
        }

       int index_value = hash_it(word2);
       node* cursor = hashtable[index_value];

       while(cursor != NULL) 
       {
         check = strcmp((cursor -> word), word2);

         if(check == 0) 
             return true;

        cursor = cursor -> next;    
      }
      return false;

      }

1 Answer 1

0

What does your hash function do? Does it return the same value for uppercase as lowercase? Most don't.

Your code hashes the word before converting it to lowercase in the check function.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

1
  • Thanks very much Cliff. It seems to work when I pass in my own files and dictionaries. However, when I check it against the staff solution I get a huge number of misspellings. Am I not dealing with the apostophies correctly?
    – user11010
    Commented Apr 12, 2016 at 12:02

You must log in to answer this question.

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