How to print f char, which always prints a single column

When I print f char with the format% c and char is not printable like "\ 0", then there is no printout column. Same thing if I use% 1c. Or% 1.1c. Is there a way to get printf to output a column for '\ 0'?

I am making a large printf file and want the columns to fit.

+3
source share
4 answers

You can do nothing for printf. But you can use isprint to filter printf arguments

printf("%c", (isprint(c) ? c : ' ' ));
+5
source

How about spelling

printf("%c",(c<' ')?' ':c);

You can easily install this in #define.

+2
source

isgraph (c)? c: ''

+1

isprint, , .

if(isprint(c)) {
   printf("%c", c);
}
else {
   print("?");
}

, .

0

All Articles