toupper

来自cppreference.com
< c‎ | string‎ | byte
在标头 <ctype.h> 定义
int toupper(int ch );

按照当前安装的 C 本地环境所定义的字符转换规则,转换给定字符为大写。

默认 "C" 本地环境中,以相应的大写字母 ABCDEFGHIJKLMNOPQRSTUVWXYZ 替换下列小写字母 abcdefghijklmnopqrstuvwxyz

目录

[编辑]参数

ch - 要转化的字符。若 ch 的值不能表示为 unsignedchar 且不等于 EOF,则行为未定义。

[编辑]返回值

ch 的大写版本,或若无大写版本列于当前 C 本地环境,则为不修改的 ch

[编辑]示例

#include <ctype.h>#include <limits.h>#include <locale.h>#include <stdio.h>   int main(void){// 在默认本地环境:for(unsignedchar l =0, u; l !=UCHAR_MAX;++l)if((u = toupper(l))!= l)printf("%c%c ", l, u);printf("\n\n");   unsignedchar c ='\xb8';// ISO-8859-15 中的字母 ž// 但在 ISO-8859-1 中为 ¸(下加符)setlocale(LC_ALL, "en_US.iso88591");printf("iso8859-1 下,toupper('0x%x') 结果为 0x%x\n", c, toupper(c));setlocale(LC_ALL, "en_US.iso885915");printf("iso8859-15 下,toupper('0x%x') 结果为 0x%x\n", c, toupper(c));}

可能的输出:

aA bB cC dD eE fF gG hH iI jJ kK lL mM nN oO pP qQ rR sS tT uU vV wW xX yY zZ   iso8859-1 下,toupper('0xb8') 结果为 0xb8 iso8859-15 下,toupper('0xb8') 结果为 0xb4

[编辑]引用

  • C23 标准(ISO/IEC 9899:2024):
  • 7.4.2.2 The toupper function (第 TBD 页)
  • C17 标准(ISO/IEC 9899:2018):
  • 7.4.2.2 The toupper function (第 147-148 页)
  • C11 标准(ISO/IEC 9899:2011):
  • 7.4.2.2 The toupper function (第 204 页)
  • C99 标准(ISO/IEC 9899:1999):
  • 7.4.2.2 The toupper function (第 185 页)
  • C89/C90 标准(ISO/IEC 9899:1990):
  • 4.3.2.2 The toupper function

[编辑]参阅

将字符转换成小写
(函数)[编辑]
转换宽字符为大写
(函数)[编辑]
toupper 的 C++ 文档
close