C语言 toupper()函数

toupper()函数

C语言中,ctype.h库中的toupper()函数的主要作用之一就是将小写的字符字母转换为大写。toupper()函数的语法如下:

int toupper(int c);

toupper()参数

参数描述
cint字符,比如'f'

toupper()返回值

字符的大写,如果传递的字符参数不是小写的字母,则返回原字符。

toupper()实例代码

如下实例,使用toupper()函数转换字符'f'和'2',看看二者的返回值有什么不同:

#include "stdio.h"
#include "ctype.h"


int main() {
    int lower_char = 'f';
    int int_char = '2';
    int r1 = toupper(lower_char);
    int r2 = toupper(int_char);
    printf("%c\n",r1);
    printf("%c\n",r2);

    return 0;

}

编译运行后,鄙人计算机输出:

F
2

免责声明:内容仅供参考,不保证正确性。


全栈后端 / C语言教程 :


















Copyright © 2022-2024 笨鸟工具 x1y1z1.com All Rights Reserved.