Thread: Unicode in C

  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
    28,413
    You could read the cprogramming.com article Unicode: What You Can Do About It Today.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    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
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    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, 12:48 AM
  2. Unicode - a lot of confusion...
    By Jumper in forum Windows Programming
    Replies: 11
    Last Post: 07-05-2004, 07:59 AM
  3. Should I go to unicode?
    By nickname_changed in forum C++ Programming
    Replies: 10
    Last Post: 10-13-2003, 11:37 AM
  4. printing non-ASCII characters (in unicode)
    By dbaryl in forum C Programming
    Replies: 1
    Last Post: 10-25-2002, 01:00 PM
  5. UNICODE and GET_STATE
    By Registered in forum C++ Programming
    Replies: 1
    Last Post: 07-15-2002, 03:23 PM