Is there a way so that when a key is pressed it will automaticlly shut down the program? Or do you always have to press enter? My program displays a line of flashing text, but I can not figure out a way to shut down the program by hitting one key and then hitting "enter".
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Is there a way so that when a key is pressed it will automaticlly shut down the program? Or do you always have to press enter? My program displays a line of flashing text, but I can not figure out a way to shut down the program by hitting one key and then hitting "enter".
it posted twice don't know why but it did, sorry about that.
Console programs are shut down with ctrl-c and other with alt-f4, but you have to make sure to free allocated memory etc.
tkorrovi
try this code...
Zero Valintine
#include <iostream>
#include <cstdlib>
#include <conio.h>
int main(){
getche();
return(0);}
Here is a small program to show one way to do that:
#include <iostream>
#include <cstring>
using namespace std;
void doneover();
int main()
{
char s[80];
char *p1;
do {
doneover();
p1 = s;
cout << "To Exit: Enter done ";
gets(p1);
} while(strcmp(s, "done"));
}
void doneover()
{
cout <<" here is your program\n" ;
}
Look for tutorials on signal handling. =)
Kip