I have a program that I want to run until interrupted by user pressing CTRL + C. When I press it nothing happens and I can only terminate the program by suspending it and manually killing it after that.
This is the part of the code that needs to run infinitely:
while(true) {
liveOrDie(field);
printOut(field);
}
The first function calculates whether to put 1 or 0 in a two dimensional array and the second one prints it out using a for loop like this:
void printOut(int field[38][102]) {
for(int i = 0; i < 38; i++) {
for(int j = 0; j < 102; j++) {
if(field[i][j] == 1) {
cout << "o";
}
else {
cout << " ";
}
}
cout << endl;
}
system("sleep .1");
}
Sleep is used so there is enough time to print everything out on the screen before it is cleared.
So, program doesn't terminate by Ctrl+C
. What may cause this behavior, and how to make the program terminate after Ctrl+C
?