2

阅读有关如何使用移位序列打印来自其他字符集的字符的信息,我得到了以下代码(我确信转义序列不正确,但我不知道为什么):

#include <stdio.h>

int main(int argc, char *argv[])
{
    printf("\x1B\x28\x49\x0E\xB3"); /* Should print: ウ */
    return 0;
}

但是,这对我不起作用,因为它输出“?” 在终端中,而不是字符“ウ”。我的字体确实支持该字符。如果有人能解释我做错了什么以及我将如何纠正这个问题(仍然使用换档序列),那将不胜感激。

谢谢

4

2 回答 2

1
于 2015-02-02T11:44:39.163 回答
1

Your are using ISO-2022-JP-3. Hence you need to write your program as follows:

int main ()
{
    // switch to JIS X 0201-1976 Kana set (1 byte per character)
    printf ("\x1B(I");

    printf ("\x33"); /* ウ */

    // mandatory switch back to ASCII before end of line
    printf ("\x1B(B");

    printf ("\n");

    return 0;
}

Note however that it is unlikely to be the character set expected by the terminal (on linux, this is most likely UTF-8). You can use iconv to perform the conversion:

$ ./main | iconv -f ISO-2022-JP-3

Alternatively you can use iconv(3) to perform the conversion inside your program.

于 2015-02-02T11:44:52.327 回答