You should use Xutf8LookupString(3) which will also take into account the input method and xkb rules in effect.
Not all keypresses directly generate a string.
Example:
#include
#include
int main(int argc, char** argv) {
KeySym keysym = 0x1a2;
Display* display = XOpenDisplay(":0");
XIM xim = XOpenIM(display, 0, 0, 0);
XIC xic = XCreateIC(xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, NULL);
XKeyPressedEvent event;
event.type = KeyPress;
event.display = display;
event.state = 0;
event.keycode = XKeysymToKeycode(display, keysym);
char buffer[32];
KeySym ignore;
Status return_status;
Xutf8LookupString(xic, &event, buffer, 32, &ignore, &return_status);
printf("%s\
", buffer);
XCloseDisplay(display);
return 0;
}