C programming: How to check whether the input string contains combination of uppercase and lowercase

后端 未结 7 874
旧时难觅i
旧时难觅i 2021-01-23 00:25

I\'m totally newbie here. As stated above, I would like to know how to check whether the input string contains combination of uppercase and lowercase. After that print a stateme

7条回答
  •  一向
    一向 (楼主)
    2021-01-23 01:03

    Something like this (which will work on both ASCII and EBCDIC platforms):

    #include 
    
    int hasMixedCase(const char *src)
    {
        int hasUpper=0, hasLower=0;
        for (;*src && !(hasUpper && hasLower);++src)
        {
            hasUpper = hasUpper || (isalpha(*src) && *src == toupper(*src));
            hasLower = hasLower || (isalpha(*src) && *src == tolower(*src));
        }
        return hasLower && hasUpper;
    }
    

提交回复
热议问题