ASCII checking and UNICODE conversion
Greetings everybody,
I need some advice for a simple program that I'm doing.
I have to take input from stdin, check for any non-ascii character and replace it with an ascii character (7bit).
I'm using fgetc and pass it an int instead of a char to check if the value is above 127. If that's the case, then proceed with the conversion.
Now, considering that different environment equals different encodings, i.e. è is 130 in ASCII and 232 in ANSI, I thought about converting the single char to UNICODE, then convert again to what it should be in 7bit ASCII, i.e. è would become e. I read about wchar_t, and came up with this (just a short summary of the full code):
Code:
int func1()
{
int i;
while ((i = fgetc(stdin)) != EOF)
{
//some code....
if (i > 127)
convert(&i);
}
return 1;
}
int convert(char *c);
{
wchar_t z = *c;
if (z == 0x00E0) //'è' in UNICODE
*c = 'e';
else...//various checkings
return 1
}
Then, just to be sure, I thought about printing z to check its value. I tried these:
Code:
printf(L"%lc", x);
printf(L"%ls", x);
printf("%lc", x);
printf("%ls", x);
and the above with wprintf(), but nothing displayed on screen.
Do you think there is something wrong with what I'm doing, both in written code or in thought process?