So I'm having a hard time trying to figure out how alarm() works.
Let's say I wanted to make a distance meter that decrements every 1 second and every 3 seconds an update will be printed out.
My problem is that the the distance never changes. I'm not sure if I'm supposed to be passing distance to update. And I'm not sure what signum is actually doing. If any light can be shed, it'd be very much appreciated.
Code:
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
int distance = 60;
void meter(int signum) {
distance = distance - 1;
alarm(1);
}
void update(int signum) {
printf("\nYou have %d feet left!\n", distance);
alarm(3);
}
int main(void) {
signal(SIGALRM, meter);
signal(SIGALRM, update);
alarm(1);
getchar();
return 0;
}