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

后端 未结 7 878
旧时难觅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:24

    unsigned int len = strlen(inputStr);
    bool containsUpperCase = false;
    bool containsLowerCase = false;
    
    for (int i = 0; i < len && !(containsUpperCase && containsLowerCase); ++i)
    {
        char c = inputStr[i];
        if (c >= 'A' && c <= 'Z')
            containsUpperCase = true;
        else  if (c >= 'a' && c <= 'z'))
            containsLowerCase = true;
    }
    
    printf("Contains Upper Case: %d Contains Lower Case: %d\n",
           containsUpperCase, containsLowerCase);
    

提交回复
热议问题