I'm writing a program that needs to ask the user a yes or no question at the end. Going based off the example .exe my teacher provided us, the line is supposed to print out "Would you like to print an Amortization Table(Y/N)?Y" and it looks for one keystroke from the user. The Y is printed out following the question like I typed, as it is supposed to represent the default choice so if the user presses [y]
, [shift + y]
, or [enter]
it goes to the function that does the amortization table and if the user presses anything else it goes to the next line When it gets the input from the user it processes the keystroke instantly as it is pressed (it does not need [enter]
to process the input) without letting the keystroke appear on the command prompt. I have tried all the functions I can think of to do this (getc, getchar, getche) but everything I have tried ends up printing the user's input. Does anyone know what function he used or what trick he is doing to keep the keystroke from appearing in the command prompt? Thanks for your help in advance, I am obviously new to programming.
Asked
Active
Viewed 33 times
0

user3010974
- 61
- 1
- 6
-
This is probably platform specific, it would be good to know what operating system you are using. – Johan Kotlinski Nov 20 '13 at 00:42
-
@kotlinski he said example .exe so probably windows... – Scotty Bauer Nov 20 '13 at 00:43
-
1possible duplicate of [How to disable echo in windows console?](http://stackoverflow.com/questions/9217908/how-to-disable-echo-in-windows-console) – Johan Kotlinski Nov 20 '13 at 00:45
1 Answers
0
For the Windows platform, use the _getch()
function from <conio.h>
to read a keypress without buffering or echo.
Read the function description on MSDN

paddy
- 60,864
- 6
- 61
- 103