|
Add what is said upstairs!
#include <setjmp.h>
#define TIMEOUT 5
static jmp_buf env;
static void sig_timeout (int sig)
{
longjmp (env, 1);
}
main ()
{
int num;
signal (SIGALRM, sig_timeout);
if (setjmp (env)! = 0)
{
printf ("Time out !!\n");
exit (-1);
}
printf ("please input a num !!\n");
alarm (TIMEOUT);
scanf ("% d",&num);
alarm (0);
printf ("u enter a num in time !!\nexit !!\n");
} |
|