toupper
From cppreference.net
|
定义于头文件
<ctype.h>
|
||
|
int
toupper
(
int
ch
)
;
|
||
根据当前安装的C语言区域设置定义的字符转换规则,将给定字符转换为大写形式。
在默认的
"C"
语言环境中,以下小写字母
abcdefghijklmnopqrstuvwxyz
会被替换为对应的大写字母
ABCDEFGHIJKLMNOPQRSTUVWXYZ
。
目录 |
参数
| ch | - | 待转换的字符。如果 ch 的值无法表示为 unsigned char 且不等于 EOF ,则行为未定义。 |
返回值
ch 的大写版本,若当前 C 本地环境中未定义大写版本则返回未修改的 ch 。
示例
运行此代码
#include <ctype.h> #include <limits.h> #include <locale.h> #include <stdio.h> int main(void) { // 在默认区域设置中: 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'; // 该字符在 ISO-8859-15 中是 ž // 在 ISO-8859-1 中是 ¸ (cedilla) 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
参考文献
- C23 标准 (ISO/IEC 9899:2024):
-
- 7.4.2.2 toupper 函数 (p: TBD)
- C17 标准 (ISO/IEC 9899:2018):
-
- 7.4.2.2 toupper 函数 (页码: 147-148)
- C11 标准 (ISO/IEC 9899:2011):
-
- 7.4.2.2 toupper 函数 (p: 204)
- C99标准(ISO/IEC 9899:1999):
-
- 7.4.2.2 toupper函数(页码:185)
- C89/C90 标准 (ISO/IEC 9899:1990):
-
- 4.3.2.2 toupper 函数
参见
|
将字符转换为小写形式
(函数) |
|
|
(C95)
|
将宽字符转换为大写形式
(函数) |
|
C++ documentation
for
toupper
|
|