473,289 Members | 1,875 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

what'd the difference between STDIN and Keyboard buffer ?

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 ?

thanks ^^
Nov 13 '05 #1
23 7647

"herrcho" <he*********@kornet.net> wrote in message
news:bk**********@news1.kornet.net...
What's the difference between STDIN and Keyboard buffer ?
As to the standard C language, nothing. Neither has
anything to do with it.

However, 'stdin' (note the lower case) is the identifier
that the C standard library uses to designate the 'standard
input stream' of a program.

C has no support for any particular hardware devices,
be they keyboards, meeces, video displays, or whatever.
All i/o is abstracted as 'streams of characters'.

when i get char through scanf, i type in some characters and press
enter,
then, where do the characters go ?
They're stored in the object whose address you must
have supplied as an argument to 'scanf()'? What
happens between the time the user presses the keys
and the point where your data is present in your
varaible depends upon your platform, and is not
addressed by the C language, which is platform
independent.

to STDIN or Keyboard buffer ? are
they same ?


See above.

BTW what is the motivation for your questions?

-Mike
Nov 13 '05 #2
Mike Wahler writes:
to STDIN or Keyboard buffer ? are
they same ?


See above.

BTW what is the motivation for your questions?


Sounds to me like another one of those guys that just like to *know* things.
Perhaps he realizes how much this irritates you.
Nov 13 '05 #3
Mike Wahler wrote:
C has no support for any particular hardware devices,
be they keyboards, meeces, video displays, or whatever.
All i/o is abstracted as 'streams of characters'.


What the h*** are "meeces"? Is that the plural for mice ;) (which in turn
is plural for mouse)?

--
Martijn
http://www.sereneconcepts.nl
Nov 13 '05 #4
Mike Wahler wrote:

"herrcho" <he*********@kornet.net> wrote in message
news:bk**********@news1.kornet.net...
What's the difference between STDIN and Keyboard buffer ?


As to the standard C language, nothing. Neither has
anything to do with it.

However, 'stdin' (note the lower case) is the identifier
that the C standard library uses to designate the 'standard
input stream' of a program.


It's a bit of sloppiness on the part of both K&R2 and the standard,
to use stdin that way.
stdin is described as being an expression of type pointer to FILE.
FILE is an object type capable of recording all the information
needed to control a stream.
The object that stdin points to,
is associated with the standard input stream.

--
pete
Nov 13 '05 #5
In <bk**********@news1.kornet.net> "herrcho" <he*********@kornet.net> writes:
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
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #6
pete writes:
It's a bit of sloppiness on the part of both K&R2 and the standard,
to use stdin that way.
stdin is described as being an expression of type pointer to FILE.
FILE is an object type capable of recording all the information
needed to control a stream.
The object that stdin points to,
is associated with the standard input stream.


I don't know what that means so I won't argue. (I don't know what "use
stdin that way" means. What is 'that'?) My answer would be that the
keyboard buffer is a useful *hardware* thing, even though the phrase itself
and the messy details are handled by software. God did not ordain that
there be a keyboard buffer. A good way to partition the workload and
minimize the number of hardware interrupts is to provide the rudiments
needed to allow keyboard buffers. If you look at a DOS era machine, you
already have the beginnings of multi-tasking: input and editing are distinct
from computing.

stdin, OTOH, is *strictly* a software concept. I am not a historian but my
first guess is that it goes back to the standard '5', or whatever, used in
Fortran I/O. Which used to be spelled FORTRAN.
Nov 13 '05 #7

"Martijn" <su*********************@hotNOFILTERmail.com> wrote in message
news:3f***********************@news.xs4all.nl...
Mike Wahler wrote:
C has no support for any particular hardware devices,
be they keyboards, meeces, video displays, or whatever.
All i/o is abstracted as 'streams of characters'.
What the h*** are "meeces"?


Me sez I can use poetic license. :-)

" Is that the plural for mice ;) (which in turn is plural for mouse)?


Something like that. Just having a bit of fun. :-)

I suppose being from NL you don't know the reference::
The old U.S. cartoon show from the sixties, "Tom and
Jerry", about two mice and their nemesis, the cat
that frequently says after being outsmarted:
"I hate those meeces to pieces!" :-)

-Mike

Nov 13 '05 #8
In <bk************@ID-179017.news.uni-berlin.de> "osmium" <r1********@comcast.net> writes:
stdin, OTOH, is *strictly* a software concept. I am not a historian but my
first guess is that it goes back to the standard '5', or whatever, used in
Fortran I/O. Which used to be spelled FORTRAN.


It's actually '*' in FORTRAN and it stands for both "standard input"
and "standard output", but I'm not sure at what point it became a standard
FORTRAN feature (it is specified by F77, but I used F-IV compilers that
didn't support it).

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #9
Mike Wahler wrote:
I suppose being from NL you don't know the reference::
The old U.S. cartoon show from the sixties, "Tom and
Jerry", about two mice and their nemesis, the cat
that frequently says after being outsmarted:
"I hate those meeces to pieces!" :-)


<cartoon pedantry>

Actually, that was from the adventures of Trixie and Dixie (the meeces)
and Jinx the cat. In classic Tom & Jerry, neither ever spoke.

</cartoon pedantry>


Brian Rodenborn
Nov 13 '05 #10

"Default User" <fi********@company.com> wrote in message
news:3F***************@company.com...
Mike Wahler wrote:
I suppose being from NL you don't know the reference::
The old U.S. cartoon show from the sixties, "Tom and
Jerry", about two mice and their nemesis, the cat
that frequently says after being outsmarted:
"I hate those meeces to pieces!" :-)


<cartoon pedantry>

Actually, that was from the adventures of Trixie and Dixie (the meeces)
and Jinx the cat. In classic Tom & Jerry, neither ever spoke.

</cartoon pedantry>


Oh, yeah, you're right.

I guess this stuff dates me pretty well, and exposes my
faulty memory. Mental segfault. :-)

-Mike
Nov 13 '05 #11
Default User wrote:
Actually, that was from the adventures of Trixie and Dixie (the meeces)
and Jinx the cat.
To be boring for a moment re "meeces": the mouse's inventor, Doug Engelbart
(who is, perhaps, the only one we might expect to have a definitive
opinion), says he "doesn't know" the plural of "mouse" (in the computer
peripheral sense), which leaves us free to use whatever name we like best.

Microsoft recommend "mouse devices", but of course everybody ignores them.
IME the mindshare seems to be split between "mice", "mouses", and "meeces"
(in descending order of popularity).
In classic Tom & Jerry, neither ever spoke.


This is an easy statement to justify, since any cartoon in which either Tom
or Jerry speaks is clearly /not/ a classic. :-)

--
Richard Heathfield : bi****@eton.powernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Nov 13 '05 #12
Richard Heathfield wrote:
Microsoft recommend "mouse devices", but of course everybody ignores them.
IME the mindshare seems to be split between "mice", "mouses", and "meeces"
(in descending order of popularity).


I prefer "mouses" myself, but "mice" seems popular around the office.
In classic Tom & Jerry, neither ever spoke.


This is an easy statement to justify, since any cartoon in which either Tom
or Jerry speaks is clearly /not/ a classic. :-)

By classic I meant created by MGM for theater(re) showings. Only some
later made-for-TV T&Js had speaking parts (and much reduced violence
levels).


Brian Rodenborn
Nov 13 '05 #13
osmium wrote:

pete writes:
It's a bit of sloppiness on the part of both K&R2 and the standard,
to use stdin that way.
stdin is described as being an expression of type pointer to FILE.
FILE is an object type capable of recording all the information
needed to control a stream.
The object that stdin points to,
is associated with the standard input stream.


I don't know what that means so I won't argue.
(I don't know what "use stdin that way" means. What is 'that'?)


"use the word 'stdin', that way"

It means that they call the standard output stream 'stdin'
even though they define 'stdin' as something else.

--
pete
Nov 13 '05 #14
pete wrote:

osmium wrote:

pete writes:
It's a bit of sloppiness on the part of both K&R2 and the standard,
to use stdin that way.
stdin is described as being an expression of type pointer to FILE.
FILE is an object type capable of recording all the information
needed to control a stream.
The object that stdin points to,
is associated with the standard input stream.
I don't know what that means so I won't argue.
(I don't know what "use stdin that way" means. What is 'that'?)


"use the word 'stdin', that way"

It means that they call the standard output stream 'stdin'


It means that they call the standard input stream 'stdin'
even though they define 'stdin' as something else.


--
pete
Nov 13 '05 #15

"pete" <pf*****@mindspring.com> wrote in message
news:3F***********@mindspring.com...
osmium wrote:

pete writes:
It's a bit of sloppiness on the part of both K&R2 and the standard,
to use stdin that way.
stdin is described as being an expression of type pointer to FILE.
FILE is an object type capable of recording all the information
needed to control a stream.
The object that stdin points to,
is associated with the standard input stream.
I don't know what that means so I won't argue.
(I don't know what "use stdin that way" means. What is 'that'?)


"use the word 'stdin', that way"

It means that they call the standard output stream 'stdin'


Really, my copy says it's called 'stdout'. :-)
even though they define 'stdin' as something else.


What something else? The standard input stream?

-Mike
Nov 13 '05 #16
Mike Wahler wrote:
"pete" <pf*****@mindspring.com> wrote in message
news:3F***********@mindspring.com...
osmium wrote:
pete writes: > stdin is described as being
> an expression of type pointer to FILE.
> FILE is an object type capable of recording all the information
> needed to control a stream.
> The object that stdin points to,
> is associated with the standard input stream.
even though they define 'stdin' as something else.


What something else? The standard input stream?


I wrote some of that post correctly.
Reread the part that I left quoted above.

Do you think that an expression of type pointer to FILE,
is a stream ?
Nov 13 '05 #17

"pete" <pf*****@mindspring.com> wrote in message
news:3F***********@mindspring.com...
Mike Wahler wrote:
"pete" <pf*****@mindspring.com> wrote in message
news:3F***********@mindspring.com...
osmium wrote:
> pete writes: > stdin is described as being
> > an expression of type pointer to FILE.
> > FILE is an object type capable of recording all the information
> > needed to control a stream.
> > The object that stdin points to,
> > is associated with the standard input stream. even though they define 'stdin' as something else.


What something else? The standard input stream?


I wrote some of that post correctly.
Reread the part that I left quoted above.

Do you think that an expression of type pointer to FILE,
is a stream ?


I think it's a pointer to a stream, with the stream
abstraction being implemented with type 'FILE'.

-Mike
Nov 13 '05 #18
Mike Wahler wrote:

"pete" <pf*****@mindspring.com> wrote in message
news:3F***********@mindspring.com...
Mike Wahler wrote:
"pete" <pf*****@mindspring.com> wrote in message
news:3F***********@mindspring.com...
> osmium wrote:
> > pete writes:

> > > stdin is described as being
> > > an expression of type pointer to FILE.
> > > FILE is an object type capable of recording all the information
> > > needed to control a stream.
> > > The object that stdin points to,
> > > is associated with the standard input stream.

> even though they define 'stdin' as something else.

What something else? The standard input stream?


I wrote some of that post correctly.
Reread the part that I left quoted above.

Do you think that an expression of type pointer to FILE,
is a stream ?


I think it's a pointer to a stream,
with the stream abstraction
being implemented with type 'FILE'.


stdin is a pointer to an object.

If stdin were a pointer to a stream, as you say it is,
then stdin still wouldn't be a stream.

--
pete
Nov 13 '05 #19
"pete" <pf*****@mindspring.com> wrote in message
news:3F***********@mindspring.com...
Mike Wahler wrote:

"pete" <pf*****@mindspring.com> wrote in message
news:3F***********@mindspring.com...
Mike Wahler wrote:
> "pete" <pf*****@mindspring.com> wrote in message
> news:3F***********@mindspring.com...
> > osmium wrote:
> > > pete writes:

> > > > stdin is described as being
> > > > an expression of type pointer to FILE.
> > > > FILE is an object type capable of recording all the information > > > > needed to control a stream.
> > > > The object that stdin points to,
> > > > is associated with the standard input stream.

> > even though they define 'stdin' as something else.
>
> What something else? The standard input stream?

I wrote some of that post correctly.
Reread the part that I left quoted above.

Do you think that an expression of type pointer to FILE,
is a stream ?
I think it's a pointer to a stream,
with the stream abstraction
being implemented with type 'FILE'.


stdin is a pointer to an object.


... which represents a stream.
If stdin were a pointer to a stream,
It's a macro that expands to a pointer to 'FILE'
as you say it is,
then stdin still wouldn't be a stream.


I didn't say that stdin is or is not a stream.
I would say that the expression 'stdin' *denotes*
a stream, which led to my 'loose' term 'pointer
to a stream'.
7.19 Input/output <stdio.h>

7.19.1 Introduction

1 The header <stdio.h> declares three types, several macros,
and many functions for performing input and output.

2 The types declared are ...

[...]

FILE

which is an object type capable of recording all the
information needed to control a stream, including its
file position indicator, a pointer to its associated
buffer (if any), an error indicator that records whether
a read/write error has occurred, and an end-of-file
indicator that records whether the end of the file has
been reached

[...]

3 The macros are ...

[...]

stderr
stdin
stdout

which are expressions of type "pointer to FILE" that
point to the FILE objects associated, respectively,
with the standard error, input, and output streams.

I don't think calling a 'FILE' an abstraction of a stream
is inaccurate.

But I suppose we're only mincing words here. :-)

-Mike
Nov 13 '05 #20
Mike Wahler wrote:

"pete" <pf*****@mindspring.com> wrote in message
news:3F***********@mindspring.com...
Mike Wahler wrote:

"pete" <pf*****@mindspring.com> wrote in message
news:3F***********@mindspring.com...
> Mike Wahler wrote: > > > even though they define 'stdin' as something else.
> >
> > What something else? The standard input stream?
At the point in the thread when you wrote that,
were you aware of the part of the standard which you quoted below,
where stdin is defined as a pointer expression ?
> I wrote some of that post correctly.
> Reread the part that I left quoted above.
>
> Do you think that an expression of type pointer to FILE,
> is a stream ?

I think it's a pointer to a stream,
with the stream abstraction
being implemented with type 'FILE'.
stdin is a pointer to an object.


.. which represents a stream.
If stdin were a pointer to a stream,


It's a macro that expands to a pointer to 'FILE'


It doesn't have to be a macro.
as you say it is,
then stdin still wouldn't be a stream.


I didn't say that stdin is or is not a stream.


Who said you did?
I would say that the expression 'stdin' *denotes* a stream,
That's one example of loose terminology.
Your quoted standard text would look pretty funny
if the standard were consistent with that usage:
stderr
stdin
stdout

which are expressions of type "pointer to FILE" that
point to the FILE objects associated, respectively,
with stderr, stdin, and stdout.

which led to my 'loose' term 'pointer to a stream'.
Loose terminology in the C standard was my point.
The meaning of stdin,
is the topic of the subject line of this thread.
7.19 Input/output <stdio.h>

7.19.1 Introduction

1 The header <stdio.h> declares three types, several macros,
and many functions for performing input and output.

2 The types declared are ...

[...]

FILE

which is an object type capable of recording all the
information needed to control a stream, including its
file position indicator, a pointer to its associated
buffer (if any), an error indicator that records whether
a read/write error has occurred, and an end-of-file
indicator that records whether the end of the file has
been reached

[...]

3 The macros are ...

[...]

stderr
stdin
stdout

which are expressions of type "pointer to FILE" that
point to the FILE objects associated, respectively,
with the standard error, input, and output streams.
Now there,
the standard is plainly describing the relationship
between stdin and the standard input stream,
and they are two different things.
I don't think calling a 'FILE' an abstraction of a stream
is inaccurate.
If you want to call that "an abstraction",
(defining two seperate things and then calling one of them
by the name of the other)
then abstraction doesn't belong in the standard,
and there is no other abstraction like that
anywhere else in the standard.
But I suppose we're only mincing words here. :-)


My answer to OP's question in the subject line is:
A keyboard is one kind file commonly associated with the
standard input stream.
stdin is a pointer expression, pointing to an object
associated with the standard input stream.

--
pete
Nov 13 '05 #21
In article <3F***********@mindspring.com>
pete <pf*****@mindspring.com> wrote (in part):
It [stdin] doesn't have to be a macro.


Actually, it *does* have to be a macro, for no good reason other
than "the standard's wording accidentally says so". You requoted
the text yourself here:
3 The macros are ...
[...]
stderr
stdin
stdout


Because this says "macros", a <stdio.h> that uses:

extern FILE *stdin, *stdout, *stderr;

(as at least one GNU-library header does) must also contain:

#define stdin stdin
#define stdout stdout
#define stderr stderr

simply so that a "compiler conformance testing suite" that uses:

#include <stdio.h>

#ifndef stdin
# error stdin is not a macro
#endif

will not fail.

(Everything else you wrote appears fine to me, and there is no good
REASON for the above as far as I know -- it just happens to be "one
of those things", as they say.)
--
In-Real-Life: Chris Torek, Wind River Systems (BSD engineering)
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://67.40.109.61/torek/index.html (for the moment)
Reading email is like searching for food in the garbage, thanks to spammers.
Nov 13 '05 #22
Chris Torek wrote:

In article <3F***********@mindspring.com>
pete <pf*****@mindspring.com> wrote (in part):
It [stdin] doesn't have to be a macro.


Actually, it *does* have to be a macro, for no good reason other
than "the standard's wording accidentally says so". You requoted
the text yourself here:
3 The macros are ...
[...]
stderr
stdin
stdout


Because this says "macros", a <stdio.h> that uses:

extern FILE *stdin, *stdout, *stderr;

(as at least one GNU-library header does) must also contain:

#define stdin stdin
#define stdout stdout
#define stderr stderr

simply so that a "compiler conformance testing suite" that uses:

#include <stdio.h>

#ifndef stdin
# error stdin is not a macro
#endif

will not fail.

(Everything else you wrote appears fine to me, and there is no good
REASON for the above as far as I know -- it just happens to be "one
of those things", as they say.)


Thank you.

--
pete
Nov 13 '05 #23
Chris Torek <no****@elf.eng.bsdi.com> wrote:

Actually, it *does* have to be a macro, for no good reason other
than "the standard's wording accidentally says so".


Indeed. There are some other things (most notably errno) that are
allowed to be either macros or identifiers with external linkage, but we
neglected to allow that license for stdin and friends. Like Chris says,
there's no good reason for it, it just never came up.

-Larry Jones

See if we can sell Mom and Dad into slavery for a star cruiser. -- Calvin
Nov 13 '05 #24

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Wodny | last post by:
Hello. Is it possible to return stdin to keyboard after redirecting it? For example after command "myprogram.exe < data.txt", when I finish reading from file I would like to be able to use...
2
by: gc | last post by:
I was having trouble getting fgets to read a string from stdin, it was reading a '\n' already in the buffer. Someone told me to rewind stdin before calling fgets. It works, but is it permissible?
5
by: hugo27 | last post by:
hugo 27, Oct 9, 2004 Ref Docs: c.l.c FAQ article 12.26 . www.digitalmars.com sitemap.stdio.fflush Reading these Docs I understand that fflush does not summarily destroy or discard the...
11
by: David Warner | last post by:
Greetings! I need to write some C code that will decide between either reading from stdin or take a file name from argv and process it. The program needs to work like all of the typical unix...
17
by: Radith | last post by:
In follow-up to my previous post; Would any one know how I can intake sentences of text (i.e. With space characters); because scanf("%s") causes input to terminate after a space character. ...
9
by: kernelxu | last post by:
hi, everyone. now, I'am confused on such a problem: function setbuf(stdin, NULL) or setvbuf(stdin, NULL, _IONBF, 0) can set the stadard input stream unbuffered. however, why does my program...
5
by: nx-2000 | last post by:
I've got a very large C# forms app and now that its being used in bigger environments we're getting a steady stream of "why does it do this?" problems. The most nagging of which right now is that...
10
by: Chad | last post by:
Given: #include <stdio.h> #include <stdlib.h> #define MAXLINE 200 int main(void) { char buff;
4
by: Adam Funk | last post by:
I'm using this sort of standard thing: for line in fileinput.input(): do_stuff(line) and wondering whether it reads until it hits an EOF and then passes lines (one at a time) into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.