I know there is a way for the user to enter input and be able to accept it without the user having to press the Enter key but I do not know the command. Does anyone here know? For example, I have a menu like this:

A Add a record
D Delete a record
L Change last name

I want the user to type an 'A' and not have to hit the Enter key. The program just accepts the 'A' automatically. Thanks for any help. :p

That's not a portable operation, so we can't offer suggestions without at least knowing your operating system. Also knowing your compiler wouldn't hurt either.

I am running Windows XP. I also have a Borland compiler. Thanks. I did not know it was not a portable command.

// assuming u know that the key code of appropriate key...
// write these statments after the menu in your program
// KEYA, KEYB are the keycodes for key A, key B ...
// u can generate key code using getch();
     case KEYA : // action when key A pressed...
     case KEYB : // action when key B pressed...
     default : //do nothing..

Edited 3 Years Ago by pyTony: fixed formating

You may use getch() or getche() function to archive this.
char ch;
case 'A':
function1(); // call funtion here

case 'B':
function2(); // call funtion here

Enjoy & Take Care!

Please check the time stamp of the last post before replying. This thread is over three years old. And use code tags when posting code.

This article has been dead for over six months. Start a new discussion instead.