c - 在 C 中打印 Unicode 符号

标签 c unicode ncurses

我正在尝试使用 C 在 linux 终端中打印一个 unicode 星号字符 ( 0x2605 )。我遵循了网站上其他答案建议的语法,但我没有得到输出:

#include <stdio.h>
#include <wchar.h>

int main(){

    wchar_t star = 0x2605;
    wprintf(L"%c\n", star);

    return 0;
}

我将不胜感激任何建议,尤其是我如何使用 ncurses 库来完成这项工作。

最佳答案

两个问题:首先,wchar_t必须以%lc格式打印,而不是%c。第二个是,除非您调用 setlocale,否则字符集设置不正确,您可能得到 ? 而不是您的星标。以下代码似乎可以工作:

#include <stdio.h>
#include <wchar.h>
#include <locale.h>

int main() {
    setlocale(LC_CTYPE, "");
    wchar_t star = 0x2605;
    wprintf(L"%lc\n", star);
}

对于 ncursesjust initialize the locale before the call to initscr .

关于c - 在 C 中打印 Unicode 符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43834315/

相关文章:

c++ - char 的 unicode 被误用于 int

c - Ncurses,非阻塞getch错过了第一个字符

比较(目标)C 中的枚举数组

c - 在预处理器指令中使用枚举值

c - 我如何只交换一个而不是两个值?

linux - ncurses 良好实践 : clear screen with windows

c - 我如何将此程序从 conio 移植到 curses?

c - 从 bison 语法文件中删除操作代码

java - 字符显示/搜索 Unicode 字符

python - BeautifulSoup : SyntaxError: invalid character in identifier