我正在尝试使用 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);
}
对于 ncurses
,just initialize the locale before the call to initscr
.
关于c - 在 C 中打印 Unicode 符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43834315/