Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Avoid having to press Enter

Reply
Thread Tools

Avoid having to press Enter

 
 
Johan Svedberg
Guest
Posts: n/a
 
      10-10-2003
Hi!

I read somewhere that it is impossible to write a program in ANSI-C
which only reads one char from the keyboard without having to press
Enter (i.e. [y/n]-questions). Is this true?

--
Johan Svedberg, http://www.velocityreviews.com/forums/(E-Mail Removed), http://johan.svedberg.pp.se/
 
Reply With Quote
 
 
 
 
Joona I Palaste
Guest
Posts: n/a
 
      10-10-2003
Johan Svedberg <(E-Mail Removed)> scribbled the following:
> Hi!


> I read somewhere that it is impossible to write a program in ANSI-C
> which only reads one char from the keyboard without having to press
> Enter (i.e. [y/n]-questions). Is this true?


That's only more-or-less true. You see, ANSI-C doesn't read anything
from the keyboard at all. Your console does. It then feeds the data to
ANSI-C via a text stream. ANSI-C can read whatever it wants from this
stream, whenever it wants, regardless of whether you press Return or
not.
The thing is, however, your console usually doesn't put the data into
the stream in the first place, until you press Return. Therefore, until
you press Return, ANSI-C is blissfully ignorant to the existence of the
data at all.
Simply switch your console from "cooked" to "raw" mode and you're all
set. How do you switch it? That's an OS question, I'm afraid, not an
ANSI-C one.

--
/-- Joona Palaste ((E-Mail Removed)) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"The question of copying music from the Internet is like a two-barreled sword."
- Finnish rap artist Ezkimo
 
Reply With Quote
 
 
 
 
pete
Guest
Posts: n/a
 
      10-11-2003
Joona I Palaste wrote:
>
> Johan Svedberg <(E-Mail Removed)> scribbled the following:
> > Hi!

>
> > I read somewhere that it is impossible to write a program in ANSI-C
> > which only reads one char from the keyboard without having to press
> > Enter (i.e. [y/n]-questions). Is this true?

>
> That's only more-or-less true. You see, ANSI-C doesn't read anything
> from the keyboard at all. Your console does.


I'm looking at my computer, my monitor and my keyboard.
I'm under the impression that my keyboard is the file
associated with the standard input stream and that my monitor
is the file associated with the standard output stream
on my system.
What's my console ?

--
pete
 
Reply With Quote
 
Joona I Palaste
Guest
Posts: n/a
 
      10-11-2003
pete <(E-Mail Removed)> scribbled the following:
> Joona I Palaste wrote:
>> Johan Svedberg <(E-Mail Removed)> scribbled the following:
>> > Hi!

>>
>> > I read somewhere that it is impossible to write a program in ANSI-C
>> > which only reads one char from the keyboard without having to press
>> > Enter (i.e. [y/n]-questions). Is this true?

>>
>> That's only more-or-less true. You see, ANSI-C doesn't read anything
>> from the keyboard at all. Your console does.


> I'm looking at my computer, my monitor and my keyboard.
> I'm under the impression that my keyboard is the file
> associated with the standard input stream and that my monitor
> is the file associated with the standard output stream
> on my system.
> What's my console ?


Your console is the program or other software component responsible
for reading from your keyboard and writing to your monitor. ANSI-C
does not provide hardware APIs to the physical devices.

--
/-- Joona Palaste ((E-Mail Removed)) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"All that flower power is no match for my glower power!"
- Montgomery Burns
 
Reply With Quote
 
pete
Guest
Posts: n/a
 
      10-15-2003
Joona I Palaste wrote:
>
> pete <(E-Mail Removed)> scribbled the following:
> > Joona I Palaste wrote:


> >> That's only more-or-less true.
> >> You see, ANSI-C doesn't read anything
> >> from the keyboard at all. Your console does.

>
> > I'm looking at my computer, my monitor and my keyboard.
> > I'm under the impression that my keyboard is the file
> > associated with the standard input stream and that my monitor
> > is the file associated with the standard output stream
> > on my system.
> > What's my console ?

>
> Your console is the program or other software component responsible
> for reading from your keyboard and writing to your monitor. ANSI-C
> does not provide hardware APIs to the physical devices.


I'm trying to understand how consoles
fit into the C standard's description of the world.
There's the computer and there are files.
The computer has an operating system (assuming not freestanding).
The flow of information between the computer and a file,
is a stream.
I guess that the console is part of the operating system,
and that the stream flows through the console, to the file.

--
pete
 
Reply With Quote
 
Joona I Palaste
Guest
Posts: n/a
 
      10-15-2003
pete <(E-Mail Removed)> scribbled the following:
> Joona I Palaste wrote:
>> pete <(E-Mail Removed)> scribbled the following:
>> > Joona I Palaste wrote:
>> >> That's only more-or-less true.
>> >> You see, ANSI-C doesn't read anything
>> >> from the keyboard at all. Your console does.

>>
>> > I'm looking at my computer, my monitor and my keyboard.
>> > I'm under the impression that my keyboard is the file
>> > associated with the standard input stream and that my monitor
>> > is the file associated with the standard output stream
>> > on my system.
>> > What's my console ?

>>
>> Your console is the program or other software component responsible
>> for reading from your keyboard and writing to your monitor. ANSI-C
>> does not provide hardware APIs to the physical devices.


> I'm trying to understand how consoles
> fit into the C standard's description of the world.
> There's the computer and there are files.
> The computer has an operating system (assuming not freestanding).
> The flow of information between the computer and a file,
> is a stream.
> I guess that the console is part of the operating system,
> and that the stream flows through the console, to the file.


Consoles are part of the operating system, yes. But the only come into
play when you are using the keyboard and the screen. There the console
goes between the actual physical devices and the streams. When using
files, the operating system connects the file directly to the streams.

--
/-- Joona Palaste ((E-Mail Removed)) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"'It can be easily shown that' means 'I saw a proof of this once (which I didn't
understand) which I can no longer remember'."
- A maths teacher
 
Reply With Quote
 
pete
Guest
Posts: n/a
 
      10-15-2003
Joona I Palaste wrote:
>
> pete <(E-Mail Removed)> scribbled the following:
> > Joona I Palaste wrote:
> >> pete <(E-Mail Removed)> scribbled the following:
> >> > Joona I Palaste wrote:
> >> >> That's only more-or-less true.
> >> >> You see, ANSI-C doesn't read anything
> >> >> from the keyboard at all. Your console does.
> >>
> >> > I'm looking at my computer, my monitor and my keyboard.
> >> > I'm under the impression that my keyboard is the file
> >> > associated with the standard input stream and that my monitor
> >> > is the file associated with the standard output stream
> >> > on my system.
> >> > What's my console ?
> >>
> >> Your console is the program or other software component responsible
> >> for reading from your keyboard and writing to your monitor. ANSI-C
> >> does not provide hardware APIs to the physical devices.

>
> > I'm trying to understand how consoles
> > fit into the C standard's description of the world.
> > There's the computer and there are files.
> > The computer has an operating system (assuming not freestanding).
> > The flow of information between the computer and a file,
> > is a stream.
> > I guess that the console is part of the operating system,
> > and that the stream flows through the console, to the file.

>
> Consoles are part of the operating system, yes. But the only come into
> play when you are using the keyboard and the screen. There the console
> goes between the actual physical devices and the streams. When using
> files, the operating system connects the file directly to the streams.


Thank you.

--
pete
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Canon XT - doing full press without wating at half-press Wolfgang Weisselberg Digital Photography 0 10-25-2010 01:37 AM
Re: Canon XT - doing full press without wating at half-press Ray Fischer Digital Photography 0 10-24-2010 06:06 AM
Avoid having a SQL express for web parts and avoid personalization Roger23 ASP .Net 2 10-12-2006 10:54 PM
capturing from text area Shft+Enter, Control+Enter, Alt+Enter and browser issue. HopfZ Javascript 0 08-28-2006 10:11 AM
Help:How to avoid button click event when Enter key is press in a TextBox? Jie ASP .Net 7 10-09-2004 02:12 PM



Advertisments