isupper() 函数原型
int isupper(int ch);
isupper()
函数根据当前 C 区域设置检查 ch 是否为大写字母。默认情况下,从 A 到 Z(ASCII 值 65 到 90)的字符是大写字母。
如果 ch 的值无法表示为 unsigned char 或不等于 EOF,则 isupper()
的行为是未定义的。
它定义在 <cctype> 头文件中。
isupper() 参数
ch: 要检查的字符。
isupper() 返回值
如果 ch 是大写字母,isupper()
函数返回非零值,否则返回零。
示例:isupper() 函数的工作原理
#include <cctype>
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
char str[] = "This Program Converts ALL UPPERCASE Characters to LOWERCASE";
for (int i=0; i<strlen(str); i++)
{
if (isupper(str[i]))
/* Converting uppercase characters to lowercase */
str[i] = str[i] + 32;
}
cout << str;
return 0;
}
运行程序后,输出将是
this program converts all uppercase characters to lowercase
另请阅读