Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

setting a timer for reading input

Status
Not open for further replies.

rjr9999

Programmer
Apr 7, 2001
183
US
Hello, i'm a fairly new programmer, and i've recently encountered a problem. How would i be able to set a timer for reading input from a user, as simply as possible?

eg.
touser - "Enter a password: " (i've been using printf here)
input
if timer exceeds 5000 miliseconds, then...
touser - "You took too long!" (again, printf)

Now, i have a timer function that works fine, but my problem is checking the timer function WHILE waiting for input...the program waits for input to be entered BEFORE it checks to see if the "5000 miliseconds" are up. I've tried scanf, and gets...if you can help, i'd be much obliged.

Thanks,
Rob
 
How you accomplish this depends on your operating environment and compiler. In other words, you can't do it with standard C functions like scanf() and <shudder> gets() which block until input has been entered by the user.

If programming in DOS, see if your compiler supports kbhit(). If you're programming in a *nix environment, see the recent thread titled &quot;Key press w/o return&quot; where I posted a *nix implementation of kbhit() using select().

If you're still unclear, post again.

Russ
bobbitts@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top