Hi, I'm doing an assignment which throws an error when meeting division-by-zero error using Signals in C library signal.h and let user input another 2 numbers, if no error just continue letting user input 2 numbers and print out quotient of them. Here is my attempt:
#include <stdio.h>
#include <signal.h>
void sign_zeroError(int sig)
{
printf("Error with 0") ;
}
int main()
{
signal(SIGFPE , sign_zeroError) ;
while(1)
{
int a , b , result;
printf("Input a: ");
scanf("%d" , &a) ;
printf("Input b: ");
scanf("%d" , &b) ;
result = a/b ;
printf("Result: %d\n" , result);
}
return 0 ;
}
The problem is that when getting the error signal, the program will go on a continuous loop and i don't know how to get back to the routine letting user input 2 numbers. I'm not used to using signal and examples in textbook don't seem to be enough, hope to hear from you guys soon, thanx a lot in advance.