/*********************************************
* @brief 将一个字符转换为大写字母
* @param ch 要转换的字符
* @return 转换后的字符
********************************************/
int towupper(int ch);
!subtitle:说明
将字符 ch 转换为大写字母。
如果 ch 的值超出 unsigned char 的范围且不等于 EOF,则是未定义行为。
!subtitle:参数
ch - 要判断的字符
!subtitle:返回值
成功时返回转换后的字符
失败时返回原本的字符
#include <stdio.h>
#include <locale.h>
#include <wchar.h>
#include <wctype.h>
int main(void) {
if (setlocale(LC_CTYPE, "zh_CN.UTF-8") == NULL) {
printf("无法设置locale\n");
return 1;
}
const wchar_t* text = L"abcdefghijklmnopqrstuvwxyz";
for (const wchar_t* ptr = text; *ptr != 0; ptr += 1)
{
wprintf(L"%lc 的大写字母是 %lc\n", *ptr, towupper(*ptr));
}
return 0;
}
运行结果:
a 的大写字母是 A
b 的大写字母是 B
c 的大写字母是 C
d 的大写字母是 D
e 的大写字母是 E
f 的大写字母是 F
g 的大写字母是 G
h 的大写字母是 H
i 的大写字母是 I
j 的大写字母是 J
k 的大写字母是 K
l 的大写字母是 L
m 的大写字母是 M
n 的大写字母是 N
o 的大写字母是 O
p 的大写字母是 P
q 的大写字母是 Q
r 的大写字母是 R
s 的大写字母是 S
t 的大写字母是 T
u 的大写字母是 U
v 的大写字母是 V
w 的大写字母是 W
x 的大写字母是 X
y 的大写字母是 Y
z 的大写字母是 Z
C11 standard (ISO/IEC 9899:2011):
7.30.3.1.2 The towupper function (p: 453)
C99 standard (ISO/IEC 9899:1999):
7.25.3.1.2 The towupper function (p: 399)