#include #include #include char msg[] = {'H', 'e', 'l', 'l', '\0', ' ', 'W', 'o', 'r', 'l', 'd'}; int main(void) { printf("%s\n", msg); size_t len = sizeof(msg) / sizeof(char); printf("%.*s (%zu)\n", (int) len, msg, len); for (size_t i = 0; i < len; ++i) { int ch = msg[i]; if (isprint(ch)) { putchar(ch); } else if (ch < 256) { printf("\\x%02x", ch); } else { // TODO support bigger ints (such as used by // ncurses that have chtype attributes on them, // or probably other cases abort(); } } putchar('\n'); }