Characters in C are really just numbers in a token table. The %c
is mainly there to do the translation between the alphanumeric token table that humans like to read/write and the raw binary that the C program uses internally.
The expression ch>='0'&&ch<='9'
evaluates to 1
or 0
which is a raw binary integer of type int
(it would be type bool
in C++). If you attempt to print that one with %c
, you'll get the symbol table character with index 0 or 1, which isn't even a printable character (0-31 aren't printable). So you print a non-printable character... either you'll see nothing or you'll see some strange symbols.
Instead you need to use %d
for printing an integer, then printf
will do the correct conversion to the printable symbols '1'
and '0'
As a side-note, make it a habit to always end your (sequence of) printf statements with \n
since that "flushes the output buffer" = actually prints to the screen, on many systems. See Why does printf not flush after the call unless a newline is in the format string? for details