C 语言 isupper()

isupper() 函数定义在 ctype.h 头文件中。它用于检查指定的字符是否为大写字母 (A-Z)。


int isupper(int argument); #where argument will be a character
 

isupper() 参数

isupper() 函数接受一个整数形式的单个参数,返回值为整数。当传递一个字符时,它会被转换为对应的 ASCII 值。

参数 描述 必需/可选
参数 要检查的字符 必需

isupper() 返回值

如果给定的字符是大写字母,isupper() 返回非零整数,否则返回零。当传递一个大写字母字符时,我们将得到一个不同的非零整数。

输入 返回值
如果参数不是大写字母
非零数字 如果参数是大写字母

isupper() 示例

示例 1:C 语言中 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

示例 2:C 语言中 isupper() 函数的工作原理


#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.