如何打印“箱式抽屉" C中的Unicode字符(Linux utf8终端)? [英] How to print "box drawers" Unicode characters in C (Linux utf8 terminal)?
问题描述
我正在尝试显示(框绘图范围:2500–257F)中的Unicode字符.它应该是标准的utf8(Unicode标准,版本6.2).我根本做不到.
I'm trying to display Unicode characters from (Box Drawing Range: 2500–257F). It's supposed to be standard utf8 (The Unicode Standard, Version 6.2). I'm simply unable to do it.
我首先尝试使用旧的ASCII字符,但是Linux终端显示在utf8中,并且没有显示任何转换(符号?).
I first tried to use the good old ASCII characters but the Linux terminal displays in utf8 and there is no conversion (symbol ?) displayed in place.
任何人都可以回答以下问题:
Could anyone answer these questions:
- 如何在C变量(
style wchar_t
)中编码Unicode字符? - 如何对Unicode使用0x或0o(十六进制,十进制)之类的转义序列?
- How to encode a unicode character in a C variable (
style wchar_t
)? - How to use the escape sequence such as 0x or 0o (hex, oct) for Unicode?
我知道U +,但似乎没有用.
I know U+ but it seems it didn't work.
setlocale(LC_ALL,"");
short a = 0x2500, b = 0x2501;
wchar_t ac = a;
wchar_t bc = b;
wprintf(L"%c%c\n", ac, bc);
exit(0);
我知道结果与所使用的字体有关,但是我使用utf8字体(http://www.unicode.org/charts/fonts.html),并且必须显示2500至257F的代码...其实不是.
I know that the results are related to the font used, but I use a utf8 font (http://www.unicode.org/charts/fonts.html) and codes from 2500 to 257F must be displayed... Actually they aren't.
感谢您的提前帮助...
Thanks for your help in advance...
推荐答案
使用包含这些字符的utf-8版本字节的Cstring.如果您打印该字符串,它将打印该字符.
Use a Cstring containing the bytes for the utf-8 versions of those characters. If You print that Cstring, it will print that character.
您的两个字符的示例:
#include <stdio.h>
int main (int argc, char *argv[])
{
char block1[] = { 0xe2, 0x94, 0x80, '\0' };
char block2[] = { 0xe2, 0x94, 0x81, '\0' };
printf("%s%s\n", block1, block2);
return 0;
}
为我打印─━
.
此外,如果您要在其中打印出包含uft-8个字符字节的Cstring,它将打印这些字符而不会出现问题. /*假设您使用gcc */ 而且IIRC gcc还是在内部使用utf-8.
Also, if You'd print a Cstring containing uft-8 character bytes somewhere in it, it would print those characters without problems. /* assuming You use gcc */ And IIRC gcc uses utf-8 internally anyway.
编辑:在我撰写本文时,您的问题有所更改.我的回答现在不那么重要了. 但是从您的症状来看-如果您看到一个?对于您期望的每个字符,我想说您的终端字体可能缺少这些字符所需的字形.
Your question changed a bit while I was writing this. And my answer is less relevant now. But from Your symptoms - if You see one ? for each character You expect, I'd say Your terminal font might be missing the glyphs required for those characters.
这篇关于如何打印“箱式抽屉" C中的Unicode字符(Linux utf8终端)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!