Re: How to print the byte representation of a wchar_t string with non -ASCII ...

From: DougEwell2@cs.com
Date: Fri Nov 02 2001 - 01:20:04 EST


In a message dated 2001-11-01 12:23:58 Pacific Standard Time,
jshin@mailaps.org writes:

> > But won't this approach fail as soon as we hit a 0x00 byte (i.e. the
> > high 8 bits of any Latin-1 character)?
>
> I'm not sure what you're alluding to here. As long as
> all characters in wstr belong to the repertoire of the encoding/
> character set of the current locale (that is, unless one
> passes wstr containing Chinese characters to printf() in,
> say, de_DE.ISO8859-1 locale),
> there should not be any problem with using '%ls' to
> print out wstr with printf(). Of course, 'printf ("%ls", wstr) '
> doesn't achieve what the original question asked for, but that
> question has already been answered, hasn't it?

OK, I freely admit that I didn't know what I was talking about and should not
have gotten involved in this question.

William Tay had originally asked:

> 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?

and I doubted (and am still surprised) that something like this would be part
of the standard library. Doesn't seem very 'C' to me. But apparently it is,
so William is in luck and I have learned something new.

-Doug Ewell
 Fullerton, California



This archive was generated by hypermail 2.1.2 : Fri Nov 02 2001 - 02:14:52 EST