0

I am currently trying to solve pset5, speller. I managed to write every funtion correctly except of the check() function. This is the check() function I wrote so far:

    // Returns true if word is in dictionary else false
    bool check(const char *word)
    {
        unsigned int bucket = hash(word);
    
        for (node *temp = table[bucket]; temp != NULL; temp = temp->next)
        {
            if (strcasecmp(temp->word, word) == 0)
            {
                return true;
            }
        }
        return false;
    }

Somehow, only strings that are either completely lowercase or completely uppercase are seen as equal to the words in the dictionary by strcsecmp. When only the first letter or any other letter or combination of letter of one string is uppercase and the rest lowercase, the function does not return 0.

I tried to solve it by using tolower() and then compare the strings but then I get an error saying something about datatypes that the strcmp() cannot be fed with.

Did I understand the strcasecmp() function wrongly? Or did I make any other mistake? I really appreciate your help!

1
  • I just realized, after changing N, the total number of 'buckets', that even CAT and cat did not result as equal. Due to my previous amount of buckets both words were put into the same bucket, wich led to some of the confusion – justforjan Nov 6 '20 at 12:00
1

Does your hash function return the same bucket for the words "apple" and "Apple"? If not, then your issue isn't strcasecmp, but the fact that you aren't looking in the right linked list.

1
  • Yes, that might be it. Only by accident CAT and cat were in the same bucket. – justforjan Nov 6 '20 at 11:59

You must log in to answer this question.

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