国际访客建议访问 Primers 编程伙伴 国际版站点 > C 教程 > towlower 以获得更好的体验。

# C 语言标准库函数 towlower

在头文件 wctype.h 中定义。
/*********************************************
 * @brief 将一个宽字符转换为小写字母
 * @param ch 要转换的宽字符
 * @return 转换后的宽字符
 ********************************************/
wint_t towlower(wint_t 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, towlower(*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

# 推荐阅读

# 外部参考

# 参考标准

  • C23 standard (ISO/IEC 9899:2024):

    • 7.30.3.1.1 The towlower function (p: TBD)

  • C17 standard (ISO/IEC 9899:2018):

    • 7.30.3.1.1 The towlower function (p: TBD)

  • C11 standard (ISO/IEC 9899:2011):

    • 7.30.3.1.1 The towlower function (p: 453)

  • C99 standard (ISO/IEC 9899:1999):

    • 7.25.3.1.1 The towlower function (p: 399)

本文 更新于: 2026-03-06 09:52:25 创建于: 2026-03-06 09:52:25