I am working in a C/C++ code that casts a char to its integer value and then needs to print it back to its char value.
But, when I try to print an "Extended ASCII" character using the printf function, it shows a different character and I can't figure out what's wrong.
int charInt = (int) 'á'; // -31
char casted = (char) charInt;
printf("%c\n", casted); // ß
If I debug the code (I'm using Visual Studio 2017), the variable 'casted' shows the correct 'á' value in IntelliSense.
I tested some different ways of printing this character, but it always has the same result:
printf("test: %d\n", (signed char)'á'); // -31
printf("test: %d\n", (unsigned char)'á'); // 225
printf("test: %c\n", -31); // ß
printf("teste: %s\n", "á"); // ß
printf("test: %c\n", 225); // ß
printf("test: %d\n", 'á'); // -31
putc(-31, stdout); // ß
What I am doing wrong ?