CE Home
Navigation
Go Back   CrazyEngineers Forum > CE : Technical Discussions > Computer Science & IT Engineering
Notices


Advertisements
Reply
 
LinkBack Thread Tools Display Modes

  #1 (permalink)
Old 14th October 2008, 02:01 PM
CE - Newbie
 
Join Date: 27th September 2008
I'm a Crazy Computer Engg. Engineer
Posts: 2
Question 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 .
!@!@!@!@!@!@!@
Gaurav sharma is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #2 (permalink)
Old 14th October 2008, 02:42 PM
CE - Regular Member
 
Join Date: 25th September 2008
I'm a Crazy CSE Engineer
Posts: 65
Default Re: C Language Input Problem In Time Bound

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");
 }
}
sriramchandrk is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Time bounded input in C programming language Gaurav sharma Computer Science & IT Engineering 3 29th September 2008 07:49 PM
Problem with graphics properties: floating run time error prabhat kumar Computer Science & IT Engineering 0 28th April 2008 06:15 PM
Time Travel - A brief overview... suyash CE - Labs 11 12th March 2008 02:40 AM
A lil problem with my PC - slow response time becool Computer Science & IT Engineering 5 21st November 2007 05:55 PM
Problem with Yahoo Messenger : Urgent help needed chaudharyssv Computer Science & IT Engineering 4 28th March 2007 12:00 AM


All times are GMT +5.5. The time now is 12:23 PM.
Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0
Member comments are owned by the poster. Copyright © 2005-2008 CrazyEngineers.com. All rights reserved.

Advertisements