I'm doing a rewrite of this question.
I want to create a string with a unicode escaped character such as "\u03B1"
using an integer constant. For example, this string is the greek letter alpha.
const char *alpha = "\u03B1"
I want to construct the same string using a call to printf using the integer value 0x03B1
. For this example it can be done like this but I'm not sure to get those two numbers from 0x03B1
.
printf("%c%c", 206, 177);
This link explains what to do but I'm not sure how to do it. http://www.fileformat.info/info/unicode/utf8.htm
For characters equal to or below 2047 (hex 0x07FF), the UTF-8 representation is spread across two bytes. The first byte will have the two high bits set and the third bit clear (i.e. 0xC2 to 0xDF). The second byte will have the top bit set and the second bit clear (i.e. 0x80 to 0xBF).
NOTE: I do not want to create the string "\\u03B1"
with a backslash. This is different than "\u03B1"
which is an escaped unicode character.