I am developing an application that uses C++ and compiles using Linux GNU C Compiler.
I want to invoke a function as the user interrupts the script using Ctrl<
You can use the signal macro.
Here is an example of how to deal with it:
#include
#include
void sigint(int a)
{
printf("^C caught\n");
}
int main()
{
signal(SIGINT, sigint);
for (;;) {}
}
Sample output:
Ethans-MacBook-Pro:~ phyrrus9$ ./a.out
^C^C caught
^C^C caught
^C^C caught
^C^C caught
^C^C caught