The loop will continue until a key is pressed, how do i reconise the key that was pressed?
Luis , Thank you for your question.
kbhit is a function, so you must give it an argument list. 'getch' will read the character.
Don't understand argument list!
How do you mean getch will read the key pressed?
could you give an example please i want the key pressed to break the loop.
Luis, Here is an example. I have not tested this. Let mw know if it does not work or if you do not understand it.
char Key = getch(); // Wait for keystroke
Char Key = getch(); Will wait for a key stroke, but it dose not get the key pressed to return a value to kbhit().
so for example if 'a' was pressed during the loop a '1' for true is returned to kbhit so it drops out of the loop, so if i type 'Char Key = getch() it will wait for me to press another key, but i want to know the key pressed to break the loop. kbhit = 1 because i pressed a key i want to know the key pressed.
Luis, You are confused about 'kbhit' and 'getch'. Here is how they work:
'kbhit' looks at the keyboard to see if the user has pressed any key. 'getch' reads a keystroke. If the user has pressed a key, 'getch' will return the character value and remove the keystroke from the console buffer.
If you want to wait until the user has pressed a key, then read it, you only have to use 'getch'.
If you want to do some processing until the user has pressed a key, then read it, you have to use 'kbhit' in the processing loop, then 'getch'.