0

So, I am trying to convert every letter of the word to lowercase but it isn't working.

Here is my code:

int compute_score(string word)
{
    // TODO: Compute and return score for string
    for (int i = 0; i < strlen(word); i++)
    {
        if (isupper(word[i]) == true)
        {
            word[i] = tolower(word[i]);
        }
        printf("%c", word[i]);
    }
    printf("\n");
    return 0;
}

Well, I looked in Debugger and what I saw was that the if statement wasn't working but I don't understand why. So I changed it to false but still it wasn't working

2
 if (isupper(word[i]) == true)

If you look at the isupper() reference and the family you will see the return value: Returns "true" (a nonzero value) if the character is an uppercase letter. As you see true, it is in quotes, that means that it is not the true of the compiler, normally true in a compiler is a Boolean value and has a value of 1 (one). Ultimately, the value returned by isupper() is a nonzero integer, not necessarily 1, hence the if condition is never verified. The solution will be to simply do:

 if (isupper(word[i]))

This condition is fulfilled whenever isupper() is nonzero.

You must log in to answer this question.

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