I have weird string that I want to inspect by printing its characters one by one. How can this be done?
I'm worried in case it has any special characters that may obstruct its printing. Can they be 'escaped'?
You could loop over the string, printing the characters one by one, and conditionally choosing to print the character or an escape sequence:
char *str, // the original string
*tmp;
for(tmp = str; *tmp; tmp++)
{
printf((iscntrl(*tmp) ? "%02x\n" : "'%c'\n"), *tmp);
}
This prints one character per line, with control characters printed in hex format.