I'm using signals in C language. The program consists in wait a few seconds for a user keyboard input if the time ends, the program terminates. However, I always have to enter text although time was over if not the program never ends. Is there any way to avoid scanf?
Here is my code
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <signal.h>
#include <sys/wait.h>
#include <stdlib.h>
#define NSECS 10
#define TRUE 1
#define FALSE 0
# define BELLS "\007\007\007"
int alarm_flag = FALSE;
void bye(){
printf("Good bye...");
}
void setflag(){
alarm_flag = TRUE;
}
int main() {
char name[20];
do {
printf("File name: \n");
scanf("%s", name);
signal(SIGALRM, setflag);
alarm(NSECS);
if (alarm_flag == TRUE){
printf(BELLS);
atexit(adios);
return 0;
} // if the user enters a file name, the program continues