In a message dated 2001-10-31 7:49:44 Pacific Standard Time,
William.Tay@usa.xerox.com writes:
> For debugging purpose, I'd like to find out how I can print the byte
> representation of a wchar_t string.
>
> Say in C, I have wchar_t wstr[10] = L"fran";
> Is there any printf or wchar equivalent function (using appropriate format
> template) that prints out the string as
> 66 72 C3 A1 6E in en_US.UTF-8 locale under UNIX?
There's nothing built in, since wchar_t is intended to be a more abstract
data type than that.
If you know the size of a wchar_t on your system, you can create a union
containing a wchar_t and as many (1-byte) chars as you need. For example, if
a wchar_t occupies 2 bytes on your system, try:
union something
{
wchar_t w;
char c[2];
};
Then cast each wchar_t in the wide string to this union, and print the values
of the plain char members.
-Doug Ewell
Fullerton, California
This archive was generated by hypermail 2.1.2 : Wed Oct 31 2001 - 12:47:20 EST