Wide Characters and tchar

Discussion in 'C Programming' started by Anitha Adusumilli, Jan 6, 2005.

  1. Hi


    Can someone pls explain the usage of wide characters and tchar?
    Also, what should I be careful about, while coding in C, to make my
    code portable and suitable for internationalization?
    ( I am looking for some tips from experienced programmers)
    Thanks
    Anitha
     
    Anitha Adusumilli, Jan 6, 2005
    #1
    1. Advertising

  2. Anitha Adusumilli wrote:
    > Can someone pls explain the usage of wide characters and tchar?
    > Also, what should I be careful about, while coding in C, to make my
    > code portable and suitable for internationalization?
    > ( I am looking for some tips from experienced programmers)


    In ISO C, the portable type for wide characters is actually wchar_t, and
    wide character strings are null-terminated arrays of these. It also
    provides a bunch of wide-character versions of ordinary C functions -
    you get them by adding "w" at various random locations or by changing
    "a" or "str" to "wcs":

    printf -> wprintf
    scanf -> wscanf
    sprintf -> swprintf
    fgetc -> fgetwc
    strcpy -> wcscpy
    atof -> wcstof

    Search for some of these to see more. There are also handy conversion
    functions for going between different types of characters and strings,
    such as btowc, wctob, mbrtowc, wcrtomb, mbsrtowcs, wcsrtombs.

    Be careful, though: there are at least three different kinds of wide
    characters in Windows, not necessarily the same, and each with their own
    API. Many API functions have versions for each kind. Pick one and stick
    with it. If your program might conceivably be ported in the future,
    wchar_t is usually your best bet.

    As for other internationalization tips, the obvious things are to keep
    any kind of text out of your code and in some centralized place and to
    not write code that depends upon properties of one language (such as
    grammar logic or even left-to-right rendering). There are some good web
    sites and books on the topic. Others might have more to say.
    --
    Derrick Coetzee
    I grant this newsgroup posting into the public domain. I disclaim all
    express or implied warranty and all liability. I am not a professional.
     
    Derrick Coetzee, Jan 6, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Web Developer

    char 8bit wide or 7bit wide in c++?

    Web Developer, Jul 31, 2003, in forum: C++
    Replies:
    2
    Views:
    607
    John Harrison
    Jul 31, 2003
  2. sorty
    Replies:
    4
    Views:
    20,804
    Rolf Magnus
    Nov 25, 2003
  3. Disc Magnet
    Replies:
    2
    Views:
    733
    Jukka K. Korpela
    May 15, 2010
  4. Disc Magnet
    Replies:
    2
    Views:
    807
    Neredbojias
    May 14, 2010
  5. Martin Rinehart

    80 columns wide? 132 columns wide?

    Martin Rinehart, Oct 31, 2008, in forum: Javascript
    Replies:
    16
    Views:
    188
    John W Kennedy
    Nov 13, 2008
Loading...

Share This Page