Jump to content
xisto Community
Sign in to follow this  
kvarnerexpress

Timeouting Program

Recommended Posts

Is there an easy way to make my 9 lines of code timeout in 5 minutes(that is no barcode has been entered for 5 mins) and if it timesout have it kill my program?


Code:

cout << "Enter barcode:\r\n";cin.get(ch);while (int(ch) != 13){       cout << ch;       cin.get(ch);       line = line+ch;}myFunction( line );

Notice from serverph:
Code enclosed in proper tags.

Edited by serverph (see edit history)

Share this post


Link to post
Share on other sites

Technically, no since std::cin halts the program until some key response occurs.
You'd have to test for keystrokes using your own code, which can take some time.

But anyway, here's you five minute time out code.

#include <iostream>#include <ctime.h>int main(){  clock_t  x;  x = clock () + 300 * CLK_TCK;  //300 seconds = 5 minutes  while (x > clock())          //basically test for 5 minutes in clock ticks    {     //place keytest code here...    }return 0;}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.