I want to have my program ignore the (Ctrl-C) signal and instead should terminate on (Ctrl-D).
How can i do that?
I want to have my program ignore the (Ctrl-C) signal and instead should terminate on (Ctrl-D).
How can i do that?
Ctrl-C is usually SIGINT, so all you need to ignore it.
Code:struct sigaction sac; if (sigaction(SIGINT, NULL, &sac) == -1) perror("Couldn't get old handler"); else { sac.sa_handler = SIG_IGN; if (sigaction(SIGINT, &sac, NULL) == -1) perror("Couldn't ignore SIGINT"); }
The information given in this message is known to work on FreeBSD 4.8 STABLE.
*The above statement is false if I was too lazy to test it.*
Please take note that I am not a technical writer, nor do I care to become one.
If someone finds a mistake, gleaming error or typo, do me a favor...bite me.
Don't assume that I'm ever entirely serious or entirely joking.
And ctrl-D generates EOF on the input stream.
Aren't you glad you learnt how to use fgets
Code:while ( fgets( buff, sizeof buff, stdin ) != NULL ) { // do stuff } if ( feof(stdin) ) { // user pressed ctrl-D }
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.