Using cin >> will pause the program until input occurs. My suggestion would be to consider using kbhit() from the non-standard conio.h file (not all compilers have this file). Sprinkle calls to kbhit() before or after any critical sections and if you want to quit only if a keystroke was made and it was a specific, then make the conditional compound. To my knowledge, which is far from all encompassing, there is no standard way to do this, though. I'll be happy to hear otherwise.
Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
Where in your code do you specify that the signal thingy is looking for Ctrl+C?
cscgal
The Queen of DaniWeb
19,422 posts since Feb 2002
Reputation Points: 1,474
Solved Threads: 230
void catch_signal(int sig_num)
{
cout<<"HEY! somebody cancelled me..."<<endl;
exit( 1 );
}
You shouldn't be putting standard output stuff in a signal handler. Search also for sig_atomic_t .
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
Something like this makes a better example (for future reference).
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
Signals and signal handlers. Thanks, folks.
Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
Try this:
int main (void){
int test = 0;
while (test < 10){
cout<<"Hello \n";
test++;
}//end of while
return 0;
}
This code will only do 9 times.
If you want to do 10 just replace while (test < 10)
with while (test <= 10).
You obviously don't test your code before you post, and are likely in for a world of hurt when you begin attempting to index into arrays.
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314