I have to write a program called BuzzOff.c. My program has to take in 3 integer arguments as such:
$ BuzzOff 10 99999 2
My program should quietly count from 0 to by 0.001 increments and
keep a running total of the resulting product of and the counter,
i.e. total += count * <arg1>;
I've read up signals but I'm still not sure how they work. How do I make my program print the current running total when it receives SIGUSR1?
This is what I have so far:
#include<stdio.h>
#include<signal.h>
float total;
void sig_handler(int signo)
{
if (signo == SIGUSR1)
printf("total: %f\n", total);
}
int main(int argc, char *argv[])
{
if( argc!=4 ) {
printf("need three arguments\n"); return(1);
}
float count;
for (count = 0; count < argv[3]; count += 0.001)
total += count*argv[2];
return 0;
}