Johan Svedberg said:
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 (
[email protected]) ---------------------------\
| 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