JSmith
JSmith

Reputation: 4808

Write Unicode with write() function

I am doing an exercise where I need to write Unicode on the terminal, using only write() in <unistd.h>.

I can't use :

Any "low level" advice on how to perform that?

Upvotes: 1

Views: 5431

Answers (1)

GroovyDotCom
GroovyDotCom

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

Related Questions