Getting keyboard input in C

D

Dave

Hey all,

Is there a function already within ANSI C that waits for character input
until a key is pressed? I know getchar() but, of course, even that waits
for a carriage return before the code moves on...


Thanks

Dave
 
M

mcheu

Hey all,

Is there a function already within ANSI C that waits for character input
until a key is pressed? I know getchar() but, of course, even that waits
for a carriage return before the code moves on...


Thanks

Dave

No. Not in ANSI or ISO C. If you're looking for something to deal
with the old "Press the any key" type situation, you'll have to step
outside of ANSI or ISO C.

On winDOS platforms, *most* compilers have these functions in the
*non-standard* conio.h header. *most*, because some compilers won't
have it at all, and some will have it as a part of some other header.

getch();

or

getche(); // if you want to echo the keypress' character equivalent
// to stdout

If you want something more portable, ncurses has similar functions
(also similarly named). Of course, you still wouldn't be dealing
strictly with standard C, as you'd be using an external library.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top