|
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
void myToupper(char* str)
{
int length = strlen(str);
for (size_t i = 0; i < length; i++)
{
if (str[i] >= 'a' && str[i] <= 'z')
{
str[i] -= 32;
// str[i] = str[i] - 'a' + 'A';
}
}
}
void myTolower(char* str)
{
int length = strlen(str);
for (size_t i = 0; i < length; i++)
{
if (str[i] >= 'A' && str[i] <= 'Z')
{
str[i] += 32;
// str[i] = str[i] - 'A' + 'a';
}
}
}
int main()
{
char str[20] = { 0 };
cout << "请输入一个包含大小写字母的字符串: " << endl;
cin.getline(str, 20);
myTolower(str);
cout << "转小写: " << str << endl;
myToupper(str);
cout << "转大写: " << str << endl;
system("pause");
return EXIT_SUCCESS;
}
[code]原文:https://blog.csdn.net/weixin_42482896/article/details/89876761 [/code] |
|