Question: Context
-------

Debian 64bits
Trying to write a int, eg 233 to a file and make it text print "é".

Question
--------

I cannot understand how i could write a utf8 equivalent char, eg "é" or any UTF-8 char largely wider than a char type can contain. The file should be human readable to send it over the network.

My goal is to write an int to a file and get its utf8 equivalent.

I don't know what I am doing.

Code
----

```
FILE * dd = fopen("/myfile.txt","w");
fprintf(dd, "%s", 233); /* The file should print "é" */
fclose(dd);

```

Thanks

UPDATE :

According to Biffen comment, here is another pices of code which writes "E9" (the hexadecimal value of "é");

```
int p = 233;
char r[5];
sprintf(r,"%x",p);
printf("%s\n",r);
fwrite(r,1,strlen(r),dd);
fclose(dd);

```

How to convert it to "é" ?

Update final working code :
===========================

```
UFILE * dd = u_fopen("/myfile.txt","wb", NULL, NULL);
UChar32 c = 233;
u_fputc(c,dd);
u_fclose(dd);

```

Answer: 
~~The standard library has [`codecvt`](http://en.cppreference.com/w/cpp/locale/codecvt) for encoding conversions, but as far as I remember GCC, for one, still doesn't have a full implementation.~~ **Edit:** Missed the [c](/questions/tagged/c "show questions tagged 'c'") tag. `codecvt` is C++.

The ‘algorithm’ for converting a Unicode codepoint to a sequence of UTF-8 units is not too complex, so you could implement it yourself fairly easily. [Here](http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=iws-appendixa)'s a page describing the procedure, and [here](http://www.unicode.org/faq/utf_bom.html)'s an other good resource.

But if you know you'll be doing a lot of Unicode-related stuff, I'd recommend using a library. [ICU](http://site.icu-project.org) is a popular choice.
One way to do this is :

```
#include <stdio.h>
#include <wchar.h>
#include <locale.h>

int main(void){
    wchar_t utfchar = 233;
    setlocale(LC_CTYPE, "");
    wprintf(L"%lc\n", utfchar);
}

```

You only need to find the corresponding `fprintf` to print to a file.