What I want to do is following: Charatcters like alphabet,numbers etc. with printf above and just the escape sequences (\t , \n etc) as hex.I want to create a char with all escape characters and check it with frequency[index].If escape sequence printf hex,if not "normal" printf like above.But it doesn't work.Could someone help me out?
#include <stdio.h>
#include <ctype.h> // isprint
int main()
{
constchar cstr[] = "ab\tcd\ne\tf\n" ;
// print one character per line, with \t \n etc. as hex
for( int i = 0 ; cstr[i] != 0 ; ++i )
{
// http://www.cplusplus.com/reference/cctype/isprint/if( isprint( cstr[i] ) ) printf( "%c\n", cstr[i] ) ; // print normal characters as they are
else printf( "%#x\n", cstr[i] ) ; // not a printable character, print its value in hexadecimal
}
}
"ab\tcd\ne\tf\n"; doesn't mean anything. It's (just) test data, which includes printable (abcdef) and non-printable (control) chars ('\t' and '\n') to show that the output logic works ok (as explained by JLBorges's comments!)