I was looking for ways to convert unicode codepoints to utf8. So far, I've learned I can do it manually or use iconv.
I also thought wctomb would work, but it doesn't:
#include <stdio.h> #include <stdlib.h> #include <arpa/inet.h> #define CENTER_UTF8 "\xf0\x9d\x8c\x86" #define CENTER_UNICODE 0x1D306 int main(int argc, char** argv) { puts(CENTER_UTF8); //OK static char buf[10]; int r; #define WCTOMB(What) \ wctomb(NULL,0); \ r=wctomb(buf,What); \ puts(buf); \ printf("r=%d\n", r); //Either one fails with -1 WCTOMB(CENTER_UNICODE); WCTOMB(htonl(CENTER_UNICODE)); } Could someone please explain to me why wctomb won't convert a unicode codepoint to utf8. I'm on Linux with a utf8 locale.