S
Steve Kobes
I ran the following program on gcc:
#include <stdio.h>
int main(void)
{
unsigned int i;
char c;
if (scanf("%x", &i) == 1)
printf("i = %u\n", i);
if (scanf("%c", &c) == 1)
printf("c = %c\n", c);
return 0;
}
I gave it the following input:
0xg
I expected the first scanf call to fail, since 'g' is not a hex digit
and "0x" is not a hex number. The 'g' would then be pushed back onto
the input stream, and the only output would be:
c = g
Instead, I got the following output:
i = 0
c = x
Is this output correct? It seems like the first scanf call must have
pushed *two* characters ('x' and 'g') back onto the input stream. Was
it supposed to?
--Steve
#include <stdio.h>
int main(void)
{
unsigned int i;
char c;
if (scanf("%x", &i) == 1)
printf("i = %u\n", i);
if (scanf("%c", &c) == 1)
printf("c = %c\n", c);
return 0;
}
I gave it the following input:
0xg
I expected the first scanf call to fail, since 'g' is not a hex digit
and "0x" is not a hex number. The 'g' would then be pushed back onto
the input stream, and the only output would be:
c = g
Instead, I got the following output:
i = 0
c = x
Is this output correct? It seems like the first scanf call must have
pushed *two* characters ('x' and 'g') back onto the input stream. Was
it supposed to?
--Steve