Finding code (c++) that enables the user to enter a menu choice without having to press the return button

Hi

I am having problems finding code (c++) that enables the user to enter a menu choice without having to press the return button

For example
Menu
Address book          1 (choices)
Phone                2 (choices)

(Say I want to choose the phone option)

What I have
2 and the press return to goto the phone function

What I want is that user should be able to enter 2 and go straight to the phone function

DYKWIM? Feel free to email me @ busin_peo@hotmail.com
busin_peoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ToHoCommented:
// Get key pressed using the getch function

int Key = getch();

switch( Key )
{
  case '1':
    AddressBook();
    break;
  case '2':
    Phone();
    break;
  default:
    cout << "Invalid choise" << endl;
}
0
SalteCommented:
Note, this is a platform issue and not a C++ issue. The problem can be solved but depends on your platform and not on the language (C++).

In windows the getch() function can be used.

In unix you can manipulate the tty so that it give you the key without waiting for return. ioctl functions to manipulate the terminal in this way exist and is easy enough.

In other platforms there are similar manners to enable reading keys from keyboard without waiting for return - but as already said, this is entirely platform dependent and has nothing to do with C++.

If this makes you wonder if you perhaps asked this question to the wrong forum the answer is "yes, you did". It has nothing to do with C++. If you go to some other forum they will probably tell you how to do it in C and the same manner can be used in C++. In fact ToHos answer above is plain C code which is also compilable in C++.

Alf
0
busin_peoAuthor Commented:
Alf

The above question above is an c++ question. As you see from the heading of my question "Finding code (c++) that enables the user to enter a menu choice without having to press the return button". Hence, the need for C++ code.

busin_peo
0
SalteCommented:
Actually it isn't. The reason why it isn't is that there is simply no solution in C++ for your problem. so if you insist it is a C++ problem the simple answer is "there is no function or C++ code that does what you want to do".

Now, if you are more practical - and most people are, most people want solutions, they're not hung up in if this is a C++ solution or a non-C++ solution - then that isn't really an answer that satisfy you. So then the more elaborate answer is "There is a platform solution to your problem but not a C++ solution. Since it is a platform solution it depends on your platform and so will vary from one OS and platform to another".

ToHo's solution works fine on Windows but will not work on Unix. A similar solution that works fine on Unix but not on windows can also be provided. However, if you sit on a Macintosh neither of those solutions will help you.

So, the point is that THERE IS NO C++ CODE THAT WILL DO WHAT YOU WANT INDEPENDENT ON PLATFORM. Again you failed to tell us which platform you're on, which you must have understood by now is of absolute necessity to be able to answer your question. I interpret this to mean that you don't really want to know the answer to your question and just want to argue about things you cannot possibly get anywhere with.

I understand that you want the C++ code and most likely whatever platform you're on, if that platform support the feature of reading characters from keyboard without waiting for return - that platform will have a solution that you can use from C++. However, the truth is still that that particular solution vary from system to system and does not vary with the language. Apart from pure syntax and name of function it is exactly the same solution in Pascal or some other language if those languages also support the same feature on that same platform. So it does not depend on language, it depends on platform. The solution given above works for windows but not for Unix or Mac.

How it is possible - after this - to still insist it is a C++ question and still not tell us which platform you want this solution for - is beyond my comprehension.

I will ignore this quetion from now on.

Alf
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tinchosCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by: Salte

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Tinchos
EE Cleanup Volunteer
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.