C语言判断是否是大写字母isupper函数

C语言isupper函数教程

C 语言 中 isupper 函数 用于判断一个 字符 是否为大写字母,如果是大写字母,则返回 1,否则,返回 0。

isupper函数详解

语法

int isupper(int c);

参数

参数 描述
c 要检查的字符。

返回值

如果 c 是一个大写字母,则该函数返回非零值(true),否则返回 0(false)。

技术细节

使用 isupper 函数,需要引入 ctype.h 头文件。

案例

C语言判断字符是否是大写字母

使用 isupper() 函数,实现判断字符是否是大写字母

#include <stdio.h> #include <ctype.h> int main() { printf("嗨客网(www.haicoder.net)\n\n"); char c1 = 'A'; char c2 = '9'; char c3 = 'a'; int isupper1 = isupper(c1); int isupper2 = isupper(c2); int isupper3 = isupper(c3); printf("isupper1 = %d, isupper2 = %d, isupper3 = %d\n", isupper1, isupper2, isupper3); return 0; }

程序运行后,控制台输出如下:

14_C语言判断字符是否是大写字母isupper函数.png

我们首先定义了三个字符 变量,分别为 c1、c2 和 c3,其中 c1 赋值为大写字母,c2 赋值为数字,c3 赋值为小写字母。接着,我们使用了 isupper 函数,分别判断了三个字符是否为大写字母。

我们可以看到,字符 c1 输出了 1,即是大写字母,而字符 c2 输出了 0,即不是大写字母,c3 也输出了 0,也不是大写字母。

C语言isupper函数总结

在 C 语言中 isupper 函数用于判断一个字符是否为大写字母,如果是大写字母,则返回 1,否则,返回 0。