Using time in C++ application?

J

Jonas Granqvist

I wonder if someone could help me with some sample code on how to make a
simple application using time. How can I for instance make the program
run the function "foobar()" every ten seconds? I've seen programs using
the time.h include file, is that the one to use?

Regards,
Jonas Granqvist
 
V

Victor Bazarov

Jonas Granqvist said:
I wonder if someone could help me with some sample code on how to make a
simple application using time. How can I for instance make the program
run the function "foobar()" every ten seconds? I've seen programs using
the time.h include file, is that the one to use?

Pseudocode:

1. Read system time (using time() function)
2. Calculate the value of what 'time' should return ten
seconds from now (using localtime() and mktime()
functions), assign it to 'future' variable
3. Call foobar()
4. Read system time.
5. If system time is the same as or greater than 'future',
go to 3. Otherwise go to 4.

Victor
 
V

Victor Bazarov

Victor Bazarov said:
Pseudocode:

1. Read system time (using time() function)
2. Calculate the value of what 'time' should return ten
seconds from now (using localtime() and mktime()
functions), assign it to 'future' variable
3. Call foobar()
4. Read system time.
5. If system time is the same as or greater than 'future',
go to 3. Otherwise go to 4.

Error. Should be

5. If system time is the same as or greater than 'future',
go to 1. Otherwise go to 4.

Victor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,112
Latest member
BrentonMcc
Top