I'm trying to show the accented letter 'is' in cmd.exe
through hexadecimal, but printf()
only shows the value of the character itself.
I'm trying the following:
unsigned char eh = 0x82;
printf("%x", eh)
I'm trying to show the accented letter 'is' in cmd.exe
through hexadecimal, but printf()
only shows the value of the character itself.
I'm trying the following:
unsigned char eh = 0x82;
printf("%x", eh)
The printf is showing hexadecimal because you used "% x", which is just that! Show value in hexadecimal:)
Just use this way, in the case of your example:
printf("%c" ,eh);
Remembering that in C ++ 11 you can use UTF-8 directly in code:
char* acentuada = u8"Acentuação";
printf("%s", acentuada);
It is important in this second to ensure that your code editor is configured for UTF-8.
Remember that in both cases, the way your environment is set up (code page, encoding pattern) can affect the output even if the input and code are right.
Of curiosity here are the main formats of printf:
d ou i Inteiro decimal com sinal 392
u Inteiro decimal sem sinal 7235
o Octal sem sinal 610
x Inteiro hexadecimal sem sinal 7fa
f Ponto flutuante decimal 392.65
e Notação científica 3.9265e+2
g %e ou %f automático (o que for mais curto) 392.65
c Caractere b
s Cadeia (string) de caracteres teste
p Endereço de ponteiro ba000000
Note that many formats that return letters such as x
and e
, for example, can be written as X
and E
if you want to output in uppercase, such as 7FA and 3,9265E + 2.
Correct is to use %c
to display the character, %s
is used to display a string of strings .
unsigned char eh = 0x82;
printf("%c", eh);