C语言编程,UNI code和Linux终端
所以,我想要做的就是写日文字符到我的终端
屏幕使用C和宽字符。
So what I'm trying to do is write Japanese characters to my terminal screen using C and wide characters.
问题是,什么是错与我在做什么,这样我可以修复它,
还有什么其他的注意事项,同时使用宽字符我应该期待和
你有什么我试图做任何其他意见?
The question is whats wrong with what I'm doing so that I can fix it, what other caveats should I expect while using wide characters and do you have any other comments about what I'm trying to do?
结果搜索结果
坏code:
The bad code:
#include <stdio.h>
#include <wchar.h>
int main( ) {
wprintf(L"%c\n", L"\x3074");
}
这是不行的,但我想知道为什么。
结果搜索结果
This doesn't work, but I want to know why.
当我尝试使用wchar_t的持有价值问题只能越来越糟:
the problem only gets worse when I try to use a wchar_t to hold a value:
wchar_t pi_0 = 0x3074; // prints a "t" when used with wprintf
wchar_t pi_1 = "\x3074"; // gives compile time warning
wchar_t pi_2 = L"\x3074"; // gives compile time warning
所以我也想使这项工作过,因为我计划有数据结构
拿着这些字符的字符串。
So I'd also like to make this work too, as I plan on having data structures holding strings of these characters.
结果搜索结果
谢谢!
Thanks!
类型的\\ x3074
是为const char []
和 L的键入\\ x3074
是常量为wchar_t []
。
如果你需要一个 wchar_t的
,使用单引号:
If you need a wchar_t
, use single quotes:
L'\x3074'
还有%C
打印字符
,但 wchar_t的
你需要一个%的LC
。