C 库函数 toupper() 使用方法及示例 - C语言教程

由网友 大卫 发布 阅读 0

 C 库函数  toupper() 使用方法及示例 - C语言教程

C 标准库 <ctype.h>

如果传递的参数是小写字母,则toupper()函数会将小写字母转换为大写字母。

C toupper() 函数原型

int toupper( int arg );

函数toupper()接受整数形式的单个参数,并返回int类型的值。

即使toupper()采用整数作为参数,字符仍然传递给函数。在内部,字符被转换为相应的ASCII值以进行检查。

如果传递的参数不是小写字母,则返回传递给函数的相同字符。

它在<ctype.h>头文件中定义。

示例:C toupper()函数

#include <stdio.h>
#include <ctype.h>
int main()
{
    char c;

    c = 'm';
    printf("%c -> %c", c, toupper(c));

    //如果传递给toupper()的字符不是小写字符,则显示传递的相同参数。
    c = 'D';
    printf("\n%c -> %c", c, toupper(c));

    c = '9';
    printf("\n%c -> %c", c, toupper(c));
    return 0;
}

输出结果

m -> M
D -> D
9 -> 9

C 标准库 <ctype.h>

C 库函数 isspace() C 库函数 isxdigit()