Re: getchar() problem
- From: CBFalconer <cbfalconer@xxxxxxxxx>
- Date: Thu, 11 May 2006 10:17:40 -0400
Alan wrote:
I am using Standard C compiled with GCC under Linux Fedora Core 4
When I run this program and enter a character at the prompt, I
have to press the ENTER key as well. This gives me 2 input
characters - 'a' and '\n' (Hex 61 and 0a)
It seems as though the getchar() function needs ENTER to
terminate reading stdin.
I am trying to get the program to respond when I press one key
only (ie without needing to press ENTER as well).
Just think about things for a moment. In general, you want to be
able to type, and correct, input on the fly. This means using
things like the backspace key. You want this editing to be done up
front, between the keyboard and your program. This means there has
to be a means of signalling "Editing done, use this". That is the
ENTER key, better known to us old fogies as 'return'.
Now think about how this is actually done, and you will see where
the term 'buffered input' comes from.
Some systems make provisions for bypassing all this. They use
non-standard features, and are thus off topic here. For discussion
of them go to a newsgroup that discusses your particular system.
--
Some informative links:
news:news.announce.newusers
http://www.geocities.com/nnqweb/
http://www.catb.org/~esr/faqs/smart-questions.html
http://www.caliburn.nl/topposting.html
http://www.netmeister.org/news/learn2quote.html
.
- References:
- getchar() problem
- From: Alan
- getchar() problem
- Prev by Date: Re: Array and Pointer Tutorial
- Next by Date: Re: Listing the most dangerous parts of C
- Previous by thread: Re: getchar() problem
- Next by thread: Re: getchar() problem
- Index(es):
Relevant Pages
|