C/C++ printing UK pound symbol from wint_t

I am on a Linux system and set the keyboard setting to UK in order to capture and print out a UK pound symbol (£).

Here is my code:

````
#include <stdio.h>
#include <wchar.h>
#include <locale.h>

int main ()
{
wint_t wc;
fputws (L"Enter text:\n", stdout);

setlocale(LC_ALL, "");
do
{
wc=getwchar();
wprintf(L"wc = %lc %d 0x%x\n", wc, wc, wc);
} while (wc != -1);

return 0;
}
````

Here is the output:

````
$ ./test
Enter text:
£
wc = GBP 163 0xa3
````

I want to print out the actual UK pound symbol (£) instead of GBP...how can I do that?
reproduces here
https://wandbox.org/permlink/2Mcibc0RATpyYJ6H

fix: move setlocale before the first I/O
https://wandbox.org/permlink/4sJFEzb9H5YUgQg0


Last edited on
Topic archived. No new replies allowed.