Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why printf doesn't print what I feed it with?

Tags:

c

encoding

printf("%s\n", "ああ");

It outputs :

ã‚ã‚

What else should I do to print it correctly?

like image 483
new_perl Avatar asked Oct 09 '11 09:10

new_perl


1 Answers

Assuming that's unicode, compile with a C99 compiler

#include <locale.h>
#include <stdio.h>
#include <wchar.h>

int main(void) {
  wchar_t buff[3]; // = L"ああ";
  buff[0] = buff[1] = L'\U00003042';
  buff[2] = 0;
  setlocale(LC_ALL, "");
  wprintf(L"%ls\n", buff);
  return 0;
}
like image 127
pmg Avatar answered Oct 11 '22 16:10

pmg