jeudi 19 novembre 2020

I'm getting an infinite true bool error when I try to compile this C code and I don't know why

This is the code

int numberofletters(string input)
{
    int count = 0;
    for(int i = 0, n = strlen(input); i < n; i++)
    {
        if (65 <= (int) input[i] <= 90 | 97 <= (int) input[i] <= 122)
        {
            count += 1;
        }
        else
        {
            count += 0;
        }
    }
    return count;
}

and here is the error message when I try to compile

~/pset2/readability/ $ make readability
clang -ggdb3 -O0 -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wshadow    readability.c  -lcrypt -lcs50 -lm -o readability
readability.c:19:34: error: result of comparison of constant 90 with boolean expression is always true [-Werror,-Wtautological-constant-out-of-range-compare]
        if (65 <= (int) input[i] <= 90 | 97 <= (int) input[i] <= 122)
            ~~~~~~~~~~~~~~~~~~~~ ^  ~~
readability.c:19:63: error: result of comparison of constant 122 with boolean expression is always true [-Werror,-Wtautological-constant-out-of-range-compare]
        if (65 <= (int) input[i] <= 90 | 97 <= (int) input[i] <= 122)
                                         ~~~~~~~~~~~~~~~~~~~~ ^  ~~~
2 errors generated.

I don't understand why this would create an infinite true statement, I'm creating two separate bounded spaces and saying if the strings ascii exists between either one then do something else do something else... Am I missing something?

Aucun commentaire:

Enregistrer un commentaire