Re: getchar() problem



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

.



Relevant Pages

  • Re: getchar() problem
    ... 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, ... It seems as though the getchar() function needs ENTER to terminate reading ...
    (comp.lang.c)
  • getchar() problem
    ... 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, ... This gives me 2 input characters - 'a' and ... Any ideas as to how I can input ONE character only? ...
    (comp.lang.c)
  • Re: WORD needs a 1st-3rd/3rd to 1st person conversion feature.
    ... He had a different toolbar for each character; each time a writer ... If you really wanted to get fancy you could have Word check your script as ... Can it do the editing for you? ...
    (microsoft.public.word.vba.general)
  • Re: Launch a doc file with Process.Start(my.doc), need to know when the file is closed.
    ... > I want to be able to launch a document or image into the proper ... > object from the database to the temp directory then calling ... > user is editing the file. ... I only want to prompt the user once. ...
    (microsoft.public.dotnet.framework)
  • Re: Opening Files
    ... I would agree for editing a document, but not for viewing ... viewing only and not prompt the user to download if they ...
    (microsoft.public.sharepoint.windowsservices)