c++如何判断字符大小写

如题所述

//判断字符是否为小写字母

boolisLower(charch)

{

returnch>='a'&&ch<='z';

}

//判断字符是否为大写字母

boolisUpper(charch)

{

returnch>='A'&&ch<='Z';

}

//判断字符是否为数字

boolisDigit(charch)

{

returnch>='0'&&ch<='9';

}

//转换为小写字母

chartoLower(charch)

{

if(ch>='A'&&ch<='Z')

returnch-'A'+'a';

else

returnch;

}

//转换为大写字母

chartoUpper(charch)

{

if(ch>='a'&&ch<='z')

returnch-'a'+'A';

else

returnch;

}

扩展资料

C语言判断字母

#include<stdio.h>

intmain()

{

charc;

printf("输入一个字符:");

scanf("%c",&c);

if((c>='a'&&c<='z')||(c>='A'&&c<='Z'))

printf("%c是字母",c);

else

printf("%c不是字母",c);

return0;

}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2016-02-04
c++判断字符大小写的方法:
#include <locale>
#include <iostream>
#include <string>
using namespace std;

int main()
{
string Test;
int count = 0;
cout << "String ?: ";
cin >> Test;
cin.get();
for(int i = 0; i < Test.length(); i++)
{
char c = Test[i];
if(isupper(c) == true)
{
count += 1;
}
}

if(count == Test.length())
{
cout << "The word is in uppercase characters" << endl;
} else
{
cout << "The word contains " << count << " lowercase characters" << endl;
}
cin.get();
}
第2个回答  推荐于2017-10-10
main()
{
scanf("%c",&c);
if(c>='a'&&c<='z')
printf("这个是小写");
else if(c>='A'&&c<='Z')
printf("这个是大写");
}本回答被提问者和网友采纳
第3个回答  2020-02-07
额……
比如说你要判断字符s
if(s<='z'&&s>='a') s就是小写字母
if(s<='Z'&&s>='A') s就是大写字母
相似回答