isupper() 函数定义在 ctype.h 头文件中。它用于检查指定的字符是否为大写字母 (A-Z)。
int isupper(int argument); #where argument will be a character
isupper() 函数接受一个整数形式的单个参数,返回值为整数。当传递一个字符时,它会被转换为对应的 ASCII 值。
| 参数 | 描述 | 必需/可选 |
|---|---|---|
| 参数 | 要检查的字符 | 必需 |
如果给定的字符是大写字母,isupper() 返回非零整数,否则返回零。当传递一个大写字母字符时,我们将得到一个不同的非零整数。
| 输入 | 返回值 |
|---|---|
| 零 | 如果参数不是大写字母 |
| 非零数字 | 如果参数是大写字母 |
#include <stdio.h>
#include <ctype.h>
int main()
{
char ch;
ch='A';
printf("If %c is passed to isupper(): %d", ch, isupper(ch));
c='a';
printf("\nIf %c is passed to isupper(): %d", ch, isupper(ch));
return 0;
}
输出
If A is passed to isupper(): 1 If a is passed to isupper(): 0
#include <stdio.h>
#include <ctype.h>
int main()
{
char ch;
printf("Please enter a character: ");
scanf("%c", &ch);
if (isupper(ch) == 0)
printf("The given %c is not an uppercase alphabet.", ch);
else
printf("The given %c is an uppercase alphabet.", ch);
return 0;
}
输出
Please enter a character: H The given H is a uppercase alphabet.