alright, so i'm using a sighandler to interpret some signal, for this purpose it is Ctrl+C, so when Ctrl+C is typed some action will be taken, and everything is fine and dandy, but what I really need is for this to happen without ^C
appearing in the input/output
for example let's say i have this code
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
void siginthandler(int param)
{
printf("User pressed Ctrl+C\n");
exit(1);
}
int main()
{
signal(SIGINT, siginthandler);
while(1);
return 0;
}
the output would be
^CUser pressed Ctrl+C
How could I get this to simply be
User pressed Ctrl+C
?
You can achieve this effect using the curses library's "noecho()" call -- but you must be willing to accept (and/or use) curses terminal handling too ...
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <curses.h>
void siginthandler(int param)
{
endwin();
printf("User pressed Ctrl+C\n");
exit(1);
}
int main()
{
initscr();
noecho();
signal(SIGINT, siginthandler);
while(1);
return 0;
}
That is most likely not your program doing that. It's likely to be the terminal drivers, in which case you should look into stty
with the ctlecho
or echoctl
options.
You can use stty -a
to get all the current settings for your terminal device. For a programmatic interface to these items, termios
is the way to go.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With