General discussion

Locked

setting timer option in C or C++

By amd_ghouse ·
Is it possible to write a program in C or C++ which will run only for specified amount of time. (for example while conducting an online exam the Question paper should appear only for specified amount of time from starting time.) Please tell me thecode for this.

This conversation is currently closed to new comments.

11 total posts (Page 1 of 2)   01 | 02   Next
| Thread display: Collapse - | Expand +

All Comments

Collapse -

setting timer option in C or C++

by sibasis75 In reply to setting timer option in C ...

Its been a long time I worked on c++ and unix but you can try this site .. I use dto get my resources here : do a "ctrl+f" and search for clock or something ... u should definitely get it

http://www.programmersheaven.com/zone3/cat33/index.htm

Collapse -

setting timer option in C or C++

by amd_ghouse In reply to setting timer option in C ...

The question was auto-closed by TechRepublic

Collapse -

setting timer option in C or C++

by //.ichael G In reply to setting timer option in C ...

What platform?
Win32 has some SetTimer functions that can either do a callback or send a WM_TIMER message to the client.

Collapse -

setting timer option in C or C++

by amd_ghouse In reply to setting timer option in C ...

The question was auto-closed by TechRepublic

Collapse -

setting timer option in C or C++

by Cedric King In reply to setting timer option in C ...

The simplest I guess would be to perform a Do While Loop while waiting for the user input. The condition would be either the user enters something which breaks from the Loop or when the time is up. For the time portion, just have a variable prior entering the Loop storing THAT time then in the Loop get the current time. If Current Time greater than the Started Time by the specified amount of time, then exit Loop too.
Hope you understand what I meant. It's basically a Loop function where two conditions are to be met for it to continue.

Collapse -

setting timer option in C or C++

by amd_ghouse In reply to setting timer option in C ...

The question was auto-closed by TechRepublic

Collapse -

setting timer option in C or C++

by lastorck In reply to setting timer option in C ...

i think so (Win32):

CreateProcess(...,&procInfo);
WaitForSingleObject(procInfo.hProcess, timeout);
TerminateProcess(procInfo.hProcess, 0);

Regards

Collapse -

setting timer option in C or C++

by amd_ghouse In reply to setting timer option in C ...

The question was auto-closed by TechRepublic

Collapse -

setting timer option in C or C++

by lastorck In reply to setting timer option in C ...

maybe so (inside process):

//...
HANDLE p = GetCurrentProcess();
GetProcessTimes(p, ...);
//...
tm = localtime(&t);
//....
if(...)
ExitProcess(0);

Regards

Collapse -

setting timer option in C or C++

by amd_ghouse In reply to setting timer option in C ...

The question was auto-closed by TechRepublic

Back to Web Development Forum
11 total posts (Page 1 of 2)   01 | 02   Next

Related Discussions

Related Forums