hi! i'm looking for a code or syntax that will make my program end if and ONLY if you press any key on the keyboard
Printable View
hi! i'm looking for a code or syntax that will make my program end if and ONLY if you press any key on the keyboard
What OS do you use?
For windows you have to use wm_char to process it
i reccomend you learn win32 programming.
You do not have to learn win32 programming just to get a program to wait for a keypress.Quote:
i reccomend you learn win32 programming.
Here, try this - Cprogramming.com FAQ > How do I get my program to wait for a keypress?
And this - SourceForge.net: Pause console - cpwiki
While this is probably what he wants, that's not specifically what he asked for.
The original request was for ending on a keypress, which very well could mean breaking out of an infinite loop that would run until a key was pressed. In that case, more details are needed.
I say, that gives all the needed information to make the code work.
We're not here to hand out solutions to how exactly you must write your code to break out of a loop when pressing a key, for example. The logic bit the programmer must do him/herself. It's imperative that the programmer knows how to create the code for certain logic.
Is this so hard?
Code:#include <conio.h>
int main()
{
while(!_kbhit());
return 0;
}