3

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?

Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261
Mutai Mwiti
  • 487
  • 1
  • 7
  • 20

1 Answers1

4

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 following s conversion specifier applies to a pointer to a wchar_t argument; or has no effect on a following a, A, e, E, f, F, g, or G conversion specifier.

Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261