C 标准库 - <ctype.h>

C 语言 toupper() 函数用于将传入的小写字母转换为大写字母。如果参数不是小写字母,则原样返回。

原型

int toupper(int argument);

返回值

若参数是小写字母(a-z),返回对应的大写字母;否则返回参数本身。

示例

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

    c = 'q';
    printf("toupper(%c) = %c\n", c, toupper(c));

    c = 'A';
    printf("toupper(%c) = %c\n", c, toupper(c));

    return 0;
}

输出:

toupper(q) = Q
toupper(A) = A

注意事项

toupper 常用于把输入统一转大写后处理,如把字母命令标准化。