在C中打印Unicode符号

Luk*_*ins 4 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;
}
Run Code Online (Sandbox Code Playgroud)

我很感激任何建议,特别是我如何使用ncurses图书馆.

Ant*_*ala 7

两个问题:首先,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);
}
Run Code Online (Sandbox Code Playgroud)