Unicode in C

This is a discussion on Unicode in C within the C Programming forums, part of the General Programming Boards category; Everything's turning to unicode now, right? How do I start using unicode instead of ASCII in my programs? I tried ...

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    58

    Unicode in C

    Everything's turning to unicode now, right? How do I start using unicode instead of ASCII in my programs? I tried changing char to wchar_t and all of the string functions into the ones from wchar.h and it works, but does that mean my program uses unicode? I just don't understand all of the crazy rules for internationalization. This is the program I tried and it works fine.
    Code:
    #include <stdio.h>
    #include <wchar.h>
    
    int main(void)
    {
        wchar_t string[20];
    
        if ( fgetws(string, 20, stdin) != NULL )
        {
            fputws(string, stdout);
        }
    }
    Is it really that easy?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,306
    You could read the cprogramming.com article Unicode: What You Can Do About It Today.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,274
    Quote Originally Posted by Banana Man View Post
    Everything's turning to unicode now, right?
    The answer is "kinda" and "not really."

    How do I start using unicode instead of ASCII in my programs? I tried changing char to wchar_t and all of the string functions into the ones from wchar.h and it works, but does that mean my program uses unicode?
    Probably not. Just making your characters "wide" isn't the same as using Unicode. You've got to actually have Unicode values in those strings, you have to have a way of displaying them, and you have to have a reliable way of streaming this data in/out of other programs. And everybody has to agree on the encoding, of which there are several.

    I just don't understand all of the crazy rules for internationalization. This is the program I tried and it works fine.
    It works fine because the data is automatically translated to a wide representation by fgetws(), and back to a screen-compatible representation by fputws(). But try, for instance, writing a wide character string literal in katakana in a C program.

    Internationalization is WAY WAY more than just 16 bit characters.

    Is it really that easy?
    Internationalization (i18n) is most definitely NOT EASY.

  4. #4
    Registered User
    Join Date
    Jan 2008
    Posts
    58
    Should I try to be compatible with unicode or is it too complicated if I don't need it?

  5. #5
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,274
    Quote Originally Posted by Banana Man View Post
    Should I try to be compatible with unicode or is it too complicated if I don't need it?
    What does "compatible with Unicode" even mean? That you can input Unicode values? Display them? What?

  6. #6
    Registered User
    Join Date
    Jan 2008
    Posts
    58
    What does "compatible with Unicode" even mean? That you can input Unicode values? Display them? What?
    Yes.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. <string> to LPCSTR? Also, character encoding: UNICODE vs ?
    By Kurisu33 in forum C++ Programming
    Replies: 7
    Last Post: 10-09-2006, 01:48 AM
  2. Unicode - a lot of confusion...
    By Jumper in forum Windows Programming
    Replies: 11
    Last Post: 07-05-2004, 08:59 AM
  3. Should I go to unicode?
    By nickname_changed in forum C++ Programming
    Replies: 10
    Last Post: 10-13-2003, 12:37 PM
  4. printing non-ASCII characters (in unicode)
    By dbaryl in forum C Programming
    Replies: 1
    Last Post: 10-25-2002, 02:00 PM
  5. UNICODE and GET_STATE
    By Registered in forum C++ Programming
    Replies: 1
    Last Post: 07-15-2002, 04:23 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21