c - 哪个 C 函数可以将 À、É 转换为小写 à、è?

标签 c locale lowercase tolower

哪个 C 函数可以将 À、É 转换为小写 à、è?

我尝试了 tolower() 和 towlower(),但都不起作用。

最佳答案

您可以使用towlower功能:

/* towlower example */
#include <stdio.h>
#include <wctype.h>
#include <wchar.h>
#include <stddef.h>
#include <locale.h>

int main () {

    setlocale(LC_CTYPE, "");
    int i=0;
    wchar_t str[] = L"À TÉst String.\n";
    wchar_t c;
    while (str[i]) {
        c = str[i];
        putwchar (towlower(c));
        i++;
    }
    return 0;
}
<小时/>

输出是:

à tést string.

> A C program inherits its locale environment variables when it starts
> up. This happens automatically. However, these variables do not
> automatically control the locale used by the library functions,
> because ANSI C says that all programs start by default in the standard
> `C' locale. To use the locales specified by the environment, you must
> call setlocale. Call it as follows:
>
> setlocale (LC_ALL, "");

“” 空名称表示根据环境变量选择区域设置。

关于c - 哪个 C 函数可以将 À、É 转换为小写 à、è?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38428135/

相关文章:

php - 使用 PHP 强制 MySQL 字段小写

Bash 将文件转换为小写并排序

c++ - 语言和地区枚举

c - C语言中Rand()基于什么算法?

c - 通过 Return 与传递指针获取数据

c - C中二维动态数组查找点

json - jq、区域设置和 strptime : how to use properly

c++ - 语言环境是否有一个定义负号的 Facet?

java - 在java中使用字符串数组时,将其转换为小写

c++ - 为什么结构的 sizeof 不等于每个成员的 sizeof 之和?