Re: wchar_t and printf not working
site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com #include <stdio.h> #include <wchar.h> #include <locale.h> int main() { setlocale(LC_CTYPE, "en_US"); wchar_t buf[] = {1040, 1041, 1042, 0}; printf("Test: %ls\n", buf); // prints "Test: АБВ" wprintf(L"Test: %ls\n", buf); // same as above return 0; } - WBR, Alexey Proskuryakov _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... On Sun, 27 Mar 2005 09:30:24 +1000 Warwick Hall <phosgate@unwired.com.au> wrote: I have downloaded expat-1.95.8 (an XML cross platform C lib) and it has the option of using UTF-16, which is passed around in wchar_t* variables. I want to print these variables out to stdout, and i am not having any luck. First of all, try running the following code. It should work, but you may need to re-configure Terminal for UTF-8 output. Wide chars in C have no encoding associated with them, and are virtually obsolete (they were introduced before Unicode emerged). Setlocale can make wprintf work in platform-dependent and not particularly reliable ways, though. Could it be that expat is assuming wchar_t is 2 bytes instead of the 4 bytes of darwin running on powerpc? The size of wchar doesn't seem relevant in this case. However, the en_US locale uses UTF-32 on Darwin, and I do not know if it's possible to specify UTF-16 (en_US.UTF-16 doesn't work). Most UTF-16 codes are equally good UTF-32 ones, so ignoring the difference may work for you while testing - but for production code this won't do, of course. This email sent to site_archiver@lists.apple.com
participants (1)
-
Alexey Proskuryakov