c - Need help understanding ungetc behavior used in conjuction with scanf -
i can't understand behaviour of program. calls scanf, followed ungetc , printf.
i not reason behind output behaviour. here code.would great if clarified behaviour.
int main() { int n=0; scanf("%d",&n); ungetc(n,stdin); printf("%d\n",n); return 0; }
output in gcc compiler , linux platform: first if give 90 waits number , after give number prints 90.
ending scanf()
format \n
instructs scanf()
expect , eat whitespace sees after number. reason looks it's waiting input, because read until gets non-whitespace character. whatever enter isn't read, rather left on stdin
subsequent reads.
Comments
Post a Comment