You have correctly noted above that you are using UTF-8. That means that you are not going to be able to use wide strings for input, since wchar_t strings require every character to be the same size (rather than some one-byte and some two-byte characters). (EDIT: Or at least I should add, I've not made it work yet. I fully admit that doesn't mean it can't be done, but.) Examples from my Mac terminal:
Code:
mini-genius:helping andrewf$ cat uc.c
#include <stdio.h>
#include <wchar.h>
#include <string.h>
#include <stdlib.h>
int main(void) {
char input[80];
wchar_t output[80];
printf("Give me something: ");
scanf("%s", input);
printf("I think you gave me %d characters.\n", strlen(input));
int foo = mbstowcs(output, input, 80);
printf("I converted %d characters, and here they are: %ls.\n", foo, output);
printf("The length of the wide string is %d.\n", wcslen(output));
return 0;
}
mini-genius:helping andrewf$ ./uc
Give me something: œ∑Ω
I think you gave me 7 characters.
I converted 7 characters, and here they are: œ∑Ω.
The length of the wide string is 7.
FURTHER EDIT: Okay so I can make it work with wide input. I would have sworn I had tried this earlier, but I must have missed a w or an l or something.
Code:
#include <locale.h>
#include <wchar.h>
int main(void) {
wchar_t c;
setlocale(LC_CTYPE, "en_US.utf8");
while (1==wscanf(L"%lc", &c)) {
wprintf(L"%x=%lc\n", c, c);
}
return 0;
}