toupper
来自 cppreference.cn
定义于头文件 <ctype.h> |
||
int toupper( int ch ); |
||
根据当前安装的 C 语言环境定义的字符转换规则,将给定字符转换为大写。
在默认的 "C" 语言环境中,以下小写字母 abcdefghijklmnopqrstuvwxyz
会被替换为相应的大写字母 ABCDEFGHIJKLMNOPQRSTUVWXYZ
。
目录 |
[edit] 参数
ch | - | 要转换的字符。如果 ch 的值不能表示为 unsigned char 且不等于 EOF,则行为未定义。 |
[edit] 返回值
字符 ch 的大写版本,或者如果当前 C 语言环境中未列出大写版本,则返回未修改的 ch。
[edit] 示例
运行此代码
#include <ctype.h> #include <limits.h> #include <locale.h> #include <stdio.h> int main(void) { // in the default locale: for (unsigned char l = 0, u; l != UCHAR_MAX; ++l) if ((u = toupper(l)) != l) printf("%c%c ", l, u); printf("\n\n"); unsigned char c = '\xb8'; // the character ž in ISO-8859-15 // but ¸ (cedilla) in ISO-8859-1 setlocale(LC_ALL, "en_US.iso88591"); printf("in iso8859-1, toupper('0x%x') gives 0x%x\n", c, toupper(c)); setlocale(LC_ALL, "en_US.iso885915"); printf("in iso8859-15, toupper('0x%x') gives 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 in iso8859-1, toupper('0xb8') gives 0xb8 in iso8859-15, toupper('0xb8') gives 0xb4
[edit] 参考文献
- C23 标准 (ISO/IEC 9899:2024)
- 7.4.2.2 toupper 函数 (页码: 待定)
- C17 标准 (ISO/IEC 9899:2018)
- 7.4.2.2 toupper 函数 (页码: 147-148)
- C11 标准 (ISO/IEC 9899:2011)
- 7.4.2.2 toupper 函数 (页码: 204)
- C99 标准 (ISO/IEC 9899:1999)
- 7.4.2.2 toupper 函数 (页码: 185)
- C89/C90 标准 (ISO/IEC 9899:1990)
- 4.3.2.2 toupper 函数
[edit] 参见
将字符转换为小写 (函数) | |
(C95) |
将宽字符转换为大写 (函数) |
C++ 文档 关于 toupper
|