Why is this code divided into several alphabetic ranges?

Asked 2 years ago, Updated 2 years ago, 151 views

When I wrote in C, I only checked the value between 'A' and 'Z' when I checked the capital letters.

inline int is_upper_alpha(char chValue)
{
    return ((chValue >= 'A') && (chValue <= 'Z'));
}

But when I looked at the code that someone else made on C++, I split the capitalization test into many different ranges. Is there a reason why you do this?

inline int is_upper_alpha(char chValue)
{
    if (((chValue >= 'A') && (chValue <= 'I')) ||
        ((chValue >= 'J') && (chValue <= 'R')) ||
        ((chValue >= 'S') && (chValue <= 'Z')))
        return 1;
    return 0;
}

c c++ character toupper

2022-09-21 17:36

1 Answers

To illustrate this, you need to know the C/C++ standard. The C/C++ standard stipulates that the character up to '0'-'9' must have a continuous value There are no rules for other char types. This may not be 'B' = 'A'+1 in the C/C++ standard.

EBCDIC is presumed to have created such a code between I-J and R-S is not a consecutive number.


2022-09-21 17:36

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.