0
Follow
4
View

Use a function to convert a string case

Mr_Sun73 注册会员
2023-02-25 12:19

if the whole a is converted, not a single character, can be changed to, hopefully help you:


#include 
#include 

int main()
{
    char a[100];
    gets(a)
    for (int i = 0; i <= strlen(a); i++) {
        if (a[i] != '\0') {
            if (a[i] >= 'A' && a[i] <= 'Z') {
                a[i] = strlwr(a[i]);
            } else if (a[i] >= 'a' && a[i] <= 'z'){
                a[i] = strupr(a[i]);
            }
        }        
    }
    
    for (int i = 0; i <= strlen(a); i++) {
        if (a[i] != '\0') {
            printf("%c", a[i]);
        }
    }
    
    return 0;

}

demon909 注册会员
2023-02-25 12:19

You loop through a function that is case-sensitive, all uppercase or lowercase of course.
Line 8 is a[i] += 32;
Replace line 12 with a[i] -=32;
, no string function

dgangd 注册会员
2023-02-25 12:19

This depends on the requirements of the problem, there are also lowercase to uppercase, uppercase to lowercase, hope to adopt

About the Author

Question Info

Publish Time
2023-02-25 12:19
Update Time
2023-02-25 12:19