0

I have couple error I don't understand them at all first case-insensitive I write strcasecmp and still have an error

    bool check(const char *word)
{
    int num = hash(word);
    for (node *c = table[num]; c != NULL; c = c->next)
    {
        if(strcasecmp(c->word, word) == 0)
        {
            return true;
        }
    }
    return false;
}

enter image description here

there is others error enter image description here

enter image description here

when I loop at all table the insensitive case solved

    bool check(const char *word)
{
    // int num = hash(word);
    for (int i = 0; i < 101; i++)
    {
        for (node *c = table[i]; c != NULL; c = c->next)
        {
            if(strcasecmp(c->word, word) == 0)
            {
                return true;
            }
        }
    }
    return false;
}

but another error still not soved

0
2

When you calculate the hash of the word being checked, have you converted the word to all lower case or are you hashing a word with upper case letters? The latter will generate a different hash result.

I'm also curious why the words in dictionary counts differ.

5
  • I should not convert letter to lower or to upper because strcasecmp do this – Mahmoud Mohamed Mar 11 '20 at 21:01
  • strcasecmp doesn't actually alter the word. It stores the string in another place temporarily, converts it there to all one case, and does the comparison there. BUT, your hash function takes the string as-is and hashes it. You need to understand that (unless the hash function converts everything to lower or upper case before hashing) that this and This will produce two different hash numbers. That's why your code fails with hash but passes when searching the entire dictionary. The word is there, but you're not looking in the right hash bucket. – Cliff B Mar 11 '20 at 21:08
  • ok and the other two problems – Mahmoud Mohamed Mar 12 '20 at 10:28
  • One question - one problem. Without seeing related code, impossible to know. But you definitely have a problem with the word counts in the dictionary. – Cliff B Mar 13 '20 at 6:04
  • Cliff, doest it mean that we don't actually need strcasecmp if we have turned all words to lower case? – Marcus Chan May 25 '20 at 14:58

You must log in to answer this question.

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