In article <uhzke.134983$AE6.11272@tornado.texas.rr.com>,
Eric Pellegrin <epellegrin2.no.spam.please.TakeThisOut@sw.rr.com> wrote:
> I'm learning C from a book that uses the getche() function from the
> <conio.h> library. However, the preprocessor/compiler (gcc 3.3 on
> Panther) doesn't recognize the function nor the library. The getchar()
> function only works line-buffered.
>
> How do I get a program to accept character input from the keyboard
> without waiting for the user to press Return?
This is not a C question. See question 19.1 in the C FAQ
<http://www.faqs.org/faqs/C-faq/faq/>:
> Q: How can I read a single character from the keyboard without
> waiting for the RETURN key? How can I stop characters from
> being echoed on the screen as they're typed?
>
> A: Alas, there is no standard or portable way to do these things in
> C. Concepts such as screens and keyboards are not even
> mentioned in the Standard, which deals only with simple I/O
> "streams" of characters.
You will have to use platform-specific stuff. Windows supports this in
its libraries, using <conio.h>.
On Mac OS X, you will have to do this by setting your terminal
characteristics, using stty. 'man stty' lists all options. Something
like:
stty raw
stty -ignbrk brkint isig
./my_executable
will probably get your terminal into the state you need.
Reinder<!-- ~MESSAGE_AFTER~ -->
>> Stay informed about: non-line-buffered key input in C