0

I'm looking for help with my (hash) code in check to properly handle misspelled words with apostrophes and substrings:

bool check(const char *word)
{
   int len = strlen(word);
   char copy[len + 1];
   copy[len] = '\0';

   for (int i = 0; i < len; i++)
   {
       if (isupper(copy[i]))
       {
           copy[i] = tolower(word[i]);
       }
       else if (islower(copy[i]))
       {
           copy[i] = word[i];
       }
       else if (copy[i] == ('\'' && i > 0))
       {
           copy[i] = word[i];
       }
   }

   int copyindex = hash(copy) % N;
   return copyindex;

   node *cursor = hashtable[copyindex];
   while (cursor != NULL)
   {
       if (strcmp(cursor->word, copy) == 0)
       {
           return true;
       }
       cursor = cursor->next;
   }
   return false;
}

1 Answer 1

0
return copyindex;

The return statement has two important uses. First, the one that matters here, forces an immediate exit from the function in which it finds itself. That is, it causes the execution of the program to return to the code that called the function. Given the point where it is, we will leave the function before checking anything in the linked list.

You must log in to answer this question.

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