471,086 Members | 1,202 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,086 software developers and data experts.

Wide Characters and tchar

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

Nov 14 '05 #1
1 2309
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.
Nov 14 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Jonathan Mcdougall | last post: by
15 posts views Thread by Steve | last post: by
3 posts views Thread by yazan jab | last post: by
1 post views Thread by jjf | last post: by
2 posts views Thread by Mick_fae_Glesga | last post: by
8 posts views Thread by Brand Bogard | last post: by
17 posts views Thread by =?Utf-8?B?R2Vvcmdl?= | last post: by
1 post views Thread by asiru | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.