I'm using C and on a *nix platform. Wondering how to make it wait for the user to hit any key to continue, or at the least the enter key. Been through 20 pages on google and many forums, keep going in loops lol.
I'm using C and on a *nix platform. Wondering how to make it wait for the user to hit any key to continue, or at the least the enter key. Been through 20 pages on google and many forums, keep going in loops lol.
Waiting for the user to press the enter key is much easier than waiting for them to press any key:
Code:#include <stdio.h> int main(void) { printf("Press ENTER to exit program"); getchar(); return 0; }
Well the standard getchar() will wait for enter to be pressed, so long as you haven't already messed up the input stream by using scanf()
You probably need to flush the input stream before calling getchar()
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
You could have always just checked the FAQ...Originally Posted by Ne0
Quzah.
Hope is the first step on the road to disappointment.
getchar() works if it's alone, I have a pretty long program with a lot of inputting so i assume i have to flush it before I want to make it wait for a key to be pressed, i could just make a function for this no problem, i read the faq and i'm pretty clueless :P Still new to C x.x After looking at that faq basically i wants me to enter all this crap each time, any easy way to make this its own function so i could essentialy do whatever(); and it flushes? Thanks
Got it Thanks!