Thread: Display Japanese Characters in C

  1. #1
    Registered User
    Join Date
    Jul 2016
    Posts
    3

    Display Japanese Characters in C

    I want to display Japanese characters with a C program.
    Is it impossible? Most webpage links redirect to C# or C++.

    I tried UTF-8 encoding and the ja_JP locale but it printed funky results, but different than the ANSII encoding.
    If I knew the format for how to input the Unicode hex or the decimal, would that work or would there still be an issue with the display? Is there a format for that?

    Eventually I am trying to add it to a big project I am working on where specifics matter, but I can play with that then. I just want to know if it's possible and if so then the general way to do it.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,168
    How about beginning by saying which OS and Compiler you're using.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jul 2016
    Posts
    3
    Windows and gnu gcc

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,168
    So what's your latest attempt?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Jul 2016
    Posts
    3
    Code:
    #include <stdio.h>
    #include <locale.h>
    #include <wchar.h>
    int main()
    {
          setlocale(LC_ALL, "ja_JP.UTF8");
          printf("%s\n", "ベギン");
          return 0;
    }
    I don't know if it's better to put in code points for the letters or not or to use something like Shift-JIS to encode.

  6. #6
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Not bad for a first attempt. First thing to know is that Windows does not support UTF8 as a narrow locale (or even "codepage", except for the MultiByte<->WideChar() api's). And code points are more portable, as far as editors and compilers go.

    Bunch of stuff to read here on that sort of stuff: Non-English characters with cout

    The end of that post shows how to do direct Unicode output to the console. Keep in mind that this still depends on the fonts being used by cmd.exe. Even in Win10, I had to change my locale to Simplified Chinese to get Kanji to render to the console - then it took me forever to get back to English since all the Windows UI was now in Chinese

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 03-21-2014, 07:19 PM
  2. Replies: 4
    Last Post: 03-17-2012, 01:37 AM
  3. Replies: 6
    Last Post: 09-23-2011, 04:07 PM
  4. How to display extended ASCII characters in LINUX
    By mocatz187 in forum C Programming
    Replies: 6
    Last Post: 01-23-2010, 12:34 AM
  5. Inconsistent display of tab characters in edit control
    By New++ in forum Windows Programming
    Replies: 0
    Last Post: 01-06-2006, 08:34 AM

Tags for this Thread