Printing UTF-8 in C

Printing UTF-8 in C

Vassilii Khachaturov vassilii at tarunz.org
Sun Jan 12 20:48:00 IST 2014


On 12.01.2014 20:34, Ori Idan wrote:
> I need to print several Hebrew characters (UTF-8) to the terminal.
> My locale is set to he_IL.UTF-8 so it shows Hebrew on the terminal, 
> however printing from C gives me Chinese characters.
> My question is how to print one character such as 'א' to the terminal.
>
Where does the character come from, is it a verbatim literal in the 
source? Unfortunately, this is not portable, even though gcc would 
support it. See the docs for GNU CPP, section "Implementation details", 
"Implementation-defined behavior". If you want portable solution, you 
must escape the chars, best done with something like #define ALEPH 
"\x..." to concatenate into a larger literal string.

Here is a nice stackoverflow thread with sample code that reads and 
outputs utf-8 from C, w/o any literals in it:
http://stackoverflow.com/questions/1373463/handling-special-characters-in-c-utf-8-encoding 
.

V.



More information about the Linux-il mailing list