Reputation: 4808
I am doing an exercise where I need to write Unicode on the terminal,
using only write() in <unistd.h>
.
I can't use :
printf
function)Any "low level" advice on how to perform that?
Upvotes: 1
Views: 5431
Reputation: 1374
As Chris wrote in the comments, you need a terminal (e.g. like xterm on Linux) that understands the Unicode and then you just write them. So by default xterm understands UTF8 and is set to a codepage such that this code will give you a UTF8 Smiley Face (☺).
#include <stdio.h>
#include <unistd.h>
char happy[] = { 0xe2, 0x98, 0xba }; /* U+263A */
int main()
{
write(1, happy, 3);
return 0;
}
Upvotes: 4