i just need to know if there is a relatively easy way to use a "hit any key" function in my program. if anyone has any ideas i would be most grateful.
Printable View
i just need to know if there is a relatively easy way to use a "hit any key" function in my program. if anyone has any ideas i would be most grateful.
If your compiler supports it, use getch(). It takes in a character then proceeds without the user having to press enter. Otherwise, make your menu say "press enter to continue" and use getc() or getchar().
P.S. I think you have to include "conio.h" to use getch().
in C++ You need to have <<endl though
example for c++:
however, my C compiler doesn't support conioCode:#include <iostream.h>
#include <conio.h>
int main()
{
cout<<"Press any key to continue"<<endl;
getch();
cout<<endl<<"Good!"<<endl;
return 0;
}
one way I did it on C (which was annoying as hell!)
Code:#include <stdio.h>
int main()
{
char ans[];
printf("Do you wish to continue? [Y/N]: ");
scanf(%c, &ans);
printf("\n");
if(ans[0] == "y" || ans[0] == "Y")
{
goto cont;
}
else { return 0; }
cont:
// Stuff for rest of code here
return 0;
}