'towlower() return "?" instead of this character in lower register

it is simple version just for ask, i have this program

wchar_t c;
wprintf(L"input\n");
wscanf(L"%d", &c);
wprintf(L"output\n");
wprintf(L"%lc", towlower(c));

and this input/output enter image description here

if i input "W" there output "?", with another characters i have the same situation.

c


Solution 1:[1]

in the line wscanf(L"%d", &c);, you passed %d as format specifier. So wscanf() is searching for an integer, but you are passing a character instead. Changing to %c will solve it.

See the specification in the wscanf(3) manpage:

   d       Matches an optionally signed decimal integer, whose format is the same
           as expected for the subject sequence of wcstol() with the value 10 for
           the  base argument. In the absence of a size modifier, the application
           shall ensure that the corresponding argument is a pointer to int.

           ...

   c       Matches  a sequence of wide characters of exactly the number specified
           by the field width (1 if no field width is present in  the  conversion
           specification).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 UnprolificToad