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 に答える