I'm having troubles understanding write() in order to print unicode caracters, unicode in the UTF-8 i'm using uses 3 bytes, so with an array of 3 char there is no problem to print them, this prints the character 'Ƹ'
:
#include <locale.h>
#include <unistd.h>
int main(void)
{
setlocale(LC_ALL, "en_US.UTF-8");
char uni[3] = {0x00, 0xC6, 0xB8};
write(1, uni, 3);
return (0);
}
The question is: if wchar_t is also 3 bytes long, and write just prints the number of bytes given by argument why the following code does not work?
#include <locale.h>
#include <wchar.h>
#include <unistd.h>
int main(void)
{
setlocale(LC_ALL, "en_US.UTF-8");
wchar_t uni = L'\xC6B8';
write(1, &uni, sizeof(wchar_t));
return (0);
}
I've tryied also to initialice wchar_t like this: wchar_t uni = 0xC6B8;
and the result is the same just two unprintable characters (��
).