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. Advertisements

  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. Advertisements

  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. Advertisements

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:
    1,189
    Dan Bishop
    Jan 26, 2004
  2. Replies:
    8
    Views:
    771
    Magnus Lycka
    Aug 5, 2005
  3. flamesrock
    Replies:
    8
    Views:
    818
    Hendrik van Rooyen
    Nov 24, 2006
  4. Ro
    Replies:
    3
    Views:
    488
    Lawrence Kirby
    Jan 26, 2005
  5. Summu82
    Replies:
    5
    Views:
    1,140
    Richard Heathfield
    Jun 7, 2006
  6. Replies:
    1
    Views:
    1,026
    Paul Boddie
    Mar 11, 2007
  7. Ron Adam

    time.time or time.clock

    Ron Adam, Jan 13, 2008, in forum: Python
    Replies:
    9
    Views:
    559
    John Machin
    Jan 14, 2008
  8. Replies:
    3
    Views:
    2,261
    Steven D'Aprano
    Jul 25, 2009
Loading...