Running this code snippet:
wchar_t *wstr = L"áßå®";
wprintf(L"%s",wstr);
gives the output:
«
instead of
áßå®
I am new to wchar_t
. How do I get the expected output?
Running this code snippet:
wchar_t *wstr = L"áßå®";
wprintf(L"%s",wstr);
gives the output:
«
instead of
áßå®
I am new to wchar_t
. How do I get the expected output?
I believe, you need to change your code
wprintf(L"%s",wstr);
to
wprintf(L"%ls",wstr);
Ref: From C11
standard, chapter §7.29.2.1, emphasis mine
l (ell)
Specifies that a following d, i, o, u, x, or X conversion specifier applies to a long int or unsigned long int argument; that a following n conversion specifier applies to a pointer to a long int argument; that a following c conversion specifier applies to a wint_t argument; that a followings
conversion specifier applies to a pointer to awchar_t
argument; or has no effect on a following a, A, e, E, f, F, g, or G conversion specifier.