C语言编程,UNI code和Linux终端 [英] C programming, unicode and the linux terminal

查看:266
本文介绍了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

这篇关于C语言编程,UNI code和Linux终端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆