I know my title may be confusing, but bear with me. I'm new to signals.
I have a program that acts like the cat
or more
unix commands, but it has a little twist. It prints out the first x lines and then allows the user to press Ctrl-/ to print out the next x lines. I know Ctrl-/
is by default used to stop the process, but I want to override it.
I want to do something along the lines of
if (user_enters = signal(SIGQUIT, sig_function))
then print the next x lines
I'm not sure how to conditionally check if the user entered the Ctrl-/
signal
right now my code forces the user to enter n to go to the next x lines, like so...
scanf(" %c", &next);
if (next == 'n'){
//loop +4 times and only print the last 4 lines
for (i = 0; i < 4; i++){
printf("%s", buf);
if (i < 3){
if (fgets(buf, sizeof(buf), file) == NULL){
fclose(file);
return 0;
}
}
}
is there a way to do this?