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
etc.

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();
if(kbhit())
          key=getch();
switch(key)
{ 
     case KEYA : // action when key A pressed...
     case KEYB : // action when key B pressed...
     .....
     default : //do nothing..
}

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

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


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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.