0

how can we see the contents of buffer assocaited with input file stream(STDIN) . suppose if we are giving input using scanf, getchar or any input function how it is actually getting stored in the buffer. especially when we press "enter" key .

example:

case:1)

$ input two integers: 10 20 (enter) $ input two integers: 10(enter) 20(enter)

case 2:

$enter two characters a b(enter) $enter two characters a(enter) b(enter)

why in case 1 it is ignoring spacebar(ASCI-32) but in case2 it is taking spacebar as next input. is it propert of scanf function or terminal .

1 Answers1

0

In the first case
Here it is ignoring the space bar because, according to the ascii character set " space " is a character whose ascii value in decimal is 32.
When "%d" encounters the value 32 it ignores it because it cannot be an integer since
the integer literals have their range between 48(0) and 57(9).

whereas

in the second case we use "%c" to input characters for which the space(ascii - 32) is
a perfectly valid input, and thus is not ignored.

You can also use %d to input characters but then you will have to provide the ascii value
for a character that you want to input, for eg:
If you want to enter and display 'A' as character then your input must be 65.

Hope this helps to clear things a bit.

Abhishek Choubey
  • 883
  • 6
  • 16
  • ok....i have understand spacebar issue. now in second case the program is taking input as spacebar or enter as second character from the input buffer. is there any tool or utility to seen input buffer associated with file stream (STDIN in this case). – debendra nath tiwary Sep 11 '14 at 06:46