I have written a program that catches <ctrl> + <c> signals and then outputs a list, but I have one compile-time error that I can’t seem to get past. I keep receiving this error:
cannot convert `void ()()’ to `void (*)(int)’ in assignment
According to the compiler the error is happening at this line of code:
handler.sa_handler = handle_SIGINT;
Here is the surrounding code as well:
cmdcounter = 1;
/*set up the signal handler*/
struct sigaction handler;
handler.sa_handler = handle_SIGINT;
sigaction(SIGINT, &handler, NULL);
strcpy(buffer, "Caught <ctrl><c>\n");
handle_SIGINT is defined earlier in the program:
void handle_SIGINT()
{
write(STDOUT_FILENO, buffer, strlen(buffer));
// Print out last 10 commands that were used.
printf("Most recent commands entered:\n");
if(cmdcounter <= 10) {
for (i=0; i < cmdcounter; i++) {
printf("%d. %s\n", i+1, cmd[i]);
}
}
else {
for (i = cmdcounter-10; i < cmdcounter; i++) {
printf("%d. %f\n", i, cmd[i]);
}
}
}
Everything looks fine to me, but something is obviously not. Does anyone know what is throwing this error?
Your function
handle_SIGINTis wrong.Show us that function, and we’ll be able to tell you exactly how it is wrong.handle_SIGINTis SUPPOSED to be:You left out the
intpart as a parameter.