What I am trying to do concerns practice with signals. I am using SIGINT and have created a signal handler that prints out a statement. (There's also a loop that gets interrupted).
Here is the code:
/* sigdemo1.c
* shows how a signal handler works.
* -run this and press ctrl-c a few times
*/
#include <string.h>
#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
#include <termios.h>
#define QUESTION "Are you sure you want to quit?"
#define MAX 10
void f(int sig);//Signal handler declaration
void loop(void);//Looping function declaration
int main(void){
signal(SIGINT, f);
for (;;)/>{
loop();
}
return 0;
}
//Signal Handler
void f(int sig){
int i;
char b[] = {'!'};
char answer[MAX];
//this is what I want to do:
//for every interrupt append a bang symbol
for(i=0; i<10; i++){
//printf("OUCH!\n");
if (i=1){
printf("OUCH%s\n",B)/>;
//if(i=2){
// printf("OUCH%s\n",b[1]);
//}
printf("Interrupt: (%d) received\n\n", sig);
}
}
printf(QUESTION);
scanf("%s", answer);
if (*answer == 'n'){
signal(SIGINT, f);
}
else
exit(1);
}
//Looping segment (infinite)
void loop(void){
printf("I am alive! HELLO!\n");
sleep(1);
}
The problem I run into is how to append the same array element (plus 1) every time the interrupt occurs. I have variants (none of them work of course). What am I missing?
Thank you (sorry for the title screw up)
This post has been edited by jinx3y: 29 April 2010 - 11:29 AM

New Topic/Question
Reply




MultiQuote






|