By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,771 Members | 1,741 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,771 IT Pros & Developers. It's quick & easy.

Using time in C++ application?

P: n/a
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

Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Jonas Granqvist" <jo**********@hotmail.com> wrote...
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
Jul 19 '05 #2

P: n/a
"Victor Bazarov" <v.********@attAbi.com> wrote...
"Jonas Granqvist" <jo**********@hotmail.com> wrote...
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.


Error. Should be

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

Victor
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.