Can anyone explain to me how to create a variable (in c), assign a Unicode character to that variable, and then print that variable. I am probably missing something here,but I can’t work it out. Also, is there any way I can include variables in a variable name?
int ttt x;
x=1;
tttx==ttt1;
I know that that code is terrible, but what should I do, as this does not seem to be the way to go about it?
To answer the second question first: No, there is no way you can include variables in the name of another variable. If you need a flexible mapping from names to values, a hash map would work well. If you can switch to C++, you can use
std::unordered_map<>for that. If you need to stick to C, you should find a library that implements hash maps and link with that. It’s easy to find numerous examples on Google, and there also several SO (Stackoverflow) questions related to that.As for the main question: If you know the Unicode code point of the character you want to print, best assign that to an
int32_tand then convert it to the desired encoding.There are various encodings for Unicode, the most widely used is UTF-8. If that is what you want, the conversion from a plain
int32_tto a UTF-8charsequence is the same as a conversion frm UCS-4 to UTF-8. There are plenty libraries available that provide functions for this conversion. For a quick overview, see here.