简体   繁体   English

交换小写字母和大写字母

[英]swapping lower letters and upper letters

#include <iostream> 
using namespace std;
int main(){
   char letter,letter1;
   cin>>letter;
   char change_to_lower(letter);
   char change_to_upper(letter);
   char  swap(letter);
   return 0;
}

char change_to_lower(char a){
    if(a=='a'&& a<='z'){
        char b= toupper(a);
        return b;
    }
}

char change_to_upper(char a){
    if(a=='A'&& a<='Z'){
        char b = tolower(a);
        return b;
    }
}

char  swap(char a){
    char letter1,letter2;
    a=change_to_lower(letter1);
    char b=change_to_upper(letter1);
    char temp = a;
    a=b;
    b=temp;
    cout<< a<<" "<< b<<endl;
    return b;
}

Do you mean to convert all uppercase characters to lowercase characters and lowercase letters to uppercase letters, in a string?您的意思是将字符串中的所有大写字符转换为小写字符,将小写字母转换为大写字母吗?

void swapuplo(char *s)
{
    size_t i;

    for (i = 0; s[i]; ++i)
        if (isupper(s[i]))
            s[i] = tolower(s[i]);
        else if (islower(s[i]))
            s[i] = toupper(s[i]);
}

This is the calling routine这是调用例程

int main()
{
    char buf[] = "HeLLo WORLD";
    swapuplo(buf);
    printf("%s\n", buf);

    getchar();
    return 0;
}

Output:输出:

hEllO world

Be sure to include <ctype.h> , which contains the declarations for the character testing functions.确保包含<ctype.h> ,其中包含字符测试函数的声明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM