Using time in C++ application?

Discussion in 'C++' started by Jonas Granqvist, Jul 19, 2003.

  1. 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
    Jonas Granqvist, Jul 19, 2003
    #1
    1. Advertising

  2. "Jonas Granqvist" <> 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
    Victor Bazarov, Jul 19, 2003
    #2
    1. Advertising

  3. "Victor Bazarov" <> wrote...
    > "Jonas Granqvist" <> 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
    Victor Bazarov, Jul 19, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. engsol
    Replies:
    2
    Views:
    946
    Dan Bishop
    Jan 26, 2004
  2. Replies:
    8
    Views:
    475
    Magnus Lycka
    Aug 5, 2005
  3. Peter Hansen
    Replies:
    0
    Views:
    712
    Peter Hansen
    Feb 22, 2006
  4. Peter Hansen
    Replies:
    0
    Views:
    605
    Peter Hansen
    Feb 22, 2006
  5. flamesrock
    Replies:
    8
    Views:
    449
    Hendrik van Rooyen
    Nov 24, 2006
Loading...

Share This Page