Why single digit numbers are appended with "D" (in C output)?
The following code
#include <stdio.h>
int main(void)
{
int c = 0;
printf("%d
", c);
return 0;
}
once compiled & ran, outputs 0
, as I would expect it to.
Though, this code
#include <stdio.h>
int main(void)
{
int c = 0;
while (getchar() != EOF) {
++c;
}
printf("%d
", c);
return 0;
}
once compiled & ran, after triggering EOF
right away -- outputs 0D
for some reason, though value of c
(as far as I can see) should be absolutely the same as in the first case.
Same happens for all the single digit numbers (i.e. 1D
, 2D
, 3D
... 9D
), starting with 10
the appending D
is not seen anymore.
I'd like to know:
Why
D
is appended to the output in the second case, but not in the first (even thoughc
should hold the same value)?Is it possible to avoid this
D
appending (and how, if it is)?