Printing wchar_t gives strange output
Executing this piece of code:
wchar_t *wstr = L"áßå®";
wprintf(L"%s",wstr);
gives the result:
"
instead
Bßå®
I am new to wchar_t
. How do you get the expected result?
I believe you need to change your code
wprintf(L"%s",wstr);
to
wprintf(L"%ls",wstr);
Ref: from the standard C11
, chapter §7.29.2.1, emphasis mine
l (ell)
Indicates that the next conversion specifier d, i, o, u, x, or X is applied to a long int or unsigned long int argument; that the next conversion pointer n is applied to a pointer to a long int argument; that the following conversion specifier c applies to the wint_t argument; that the next conversion pointers
is applied to the argument pointerwchar_t
; or does not affect the following conversions a, A, e, E, f, F, g, or G specifier.