2

I am looking for a way of printing characters which are represented in UTF-8 as an array of bytes. I've found this approach (below), but I didn't get the expected result あ. Instead of it, I got Russian letters уБВ.

#include <stdio.h>
#include <conio.h>

int main()
{
    char s[]={0xe3,0x81,0x82, 0x00};
    printf("%s",s);
    _getch();
    return 0;
}

Could you kindly advise me the best way of printing utf-8 strings in console? (It is necessary for parsing asn.1 utf-8 strings.)

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
MyName
  • 357
  • 2
  • 4
  • 15
  • although the dupe I linked is for C++, the answer is *exactly* the same. Firstly, you'd have to define what you mean by "console" - different TTYs will act differently vs character encodings. –  Aug 09 '16 at 23:22
  • 3
    Your code is printing UTF-8. Your *terminal* is not interpreting it as UTF-8, however. – Tavian Barnes Aug 09 '16 at 23:24
  • 2
    @TavianBarnes is correct. I compiled your code and I get あ while on ubuntu terminal ... Please run this in your console echo -e '\xe2\x82\xac' ... you will see € if your console is UNF-8 – Scott Stensland Aug 09 '16 at 23:34
  • Mac OS X 10.11.6 is also OK with displaying the hiragana. – Jonathan Leffler Aug 09 '16 at 23:46

0 Answers0