Hi Gaurav,
I had given a hint to use alarm command, but looks like you dont have much time.
Hope this is useful
Please give credit to me while using this code!! ( just joking)
Thanks & Regards
Sriram
Code:
#include <stdio.h>
#include <signal.h>
void catch_timeout (int sig)
{
printf("\nSorry Timeout!!\n");
signal(SIGALRM, catch_timeout); //reinstall singal handler
}
int main()
{
unsigned u, ret;
signal(SIGALRM, catch_timeout); //install signal handler
printf("Please give value of u in 4 seconds!:");
ret = alarm(4);
scanf("%u", &u);
alarm(0);// in all cases you need to reset alarm
if(!ret)
{
printf("timeout so moving ahead withe default values for\n");
}
// second try
printf("Please give value of u in atleast in 5 seconds!:");
ret = alarm(5);
scanf("%u", &u);
alarm(0);//in all cases you need to reset alarm
if(!ret)
{
printf("timeout again so moving ahead withe default values for\n");
}
}