C Language Input Problem In Time Bound

😁
i want know that how can a program get time bounded input in "C Language"...
i want to ask that when a user input he has only few seconds which i will define as 3 seconds ..
if user not input within 3 second nextline should be compile....
πŸ˜•
plzzz don't say me "delay" or "sleep" command can use ...
i have already try it ....
i am not understand how this work on this situation ...
plzzz send me a example....
πŸ˜’
but i don't think so that this problem can be solved by the "sleep/delay" command ..
it may there is a different keyword/function /command
which can solve the problem of time bounded input in "C Language"

plzzz help me .
!@!@!@!@!@!@!@:smile:

Replies

  • sriramchandrk
    sriramchandrk
    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

    #include 
    #include 
     
    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");
     }
    }
     
    

You are reading an archived discussion.

Related Posts

Hi CE's i hope everyone follows 'CE RULES'.......😁 Enjoy😁 All discussions must happen on CE Forums. Providing email ID only invites spammers.
Those who are searching for professional yet free πŸ˜‰ themes for their wordpress blogs - Visit: 10 professional looking Wordpress themes Others, please add more links.
Hi Guys, Can you solve this? Problem: Find the nth biggest number in an array! Input: array of numbers, n Output: n biggest in the array. Example: Array = {...
Find integers a, b and c such that :- 987654321a + 123456789b + c = (a + b + c)Β³ There are (at least) 3 solutions with a and b...
HELLO to all, 😎