In said:
What's the difference between STDIN and Keyboard buffer ?
when i get char through scanf, i type in some characters and press
enter,
then, where do the characters go ? to STDIN or Keyboard buffer ? are
they same ?
Your question makes sense only if stdin is connected to an interactive
terminal. Although this is quite common, keep in mind that it is not
necessarily the case, on many implementations stdin can be connected
to a file or some other kind of device.
To understand the difference between stdin and keyboard buffer, you
must realise that stdin is a C library concept and it is implemented at
that level, while the keyboard buffer is an operating system concept (and
implemented at that level).
So, the characters you type go into the keyboard buffer (you may type them
even at a time when the program doesn't wait for stdin input, so something
must take care of them). When your program needs input from stdin, an
input function from the standard library implementation asks the OS to
deliver the contents of the keyboard buffer as soon as it may be made
available to the program. At that point, the characters get moved from
the keyboard buffer into stdin's buffer.
Of course, this is not the only scenario possible in practice and things
are also affected by the buffering mode of stdin (line-buffered or
non-buffered) and by the buffering mode of the terminal driver of your OS
(characters may be delivered to the application only when a newline is
already in the keyboard buffer or at any time). But you get a general
idea about the difference between the two.
Dan