Wide Characters and tchar

  • Thread starter Anitha Adusumilli
  • Start date
A

Anitha Adusumilli

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
 
D

Derrick Coetzee

Anitha said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top