updating the clock ?

This is a discussion on updating the clock ? within the C Programming forums, part of the General Programming Boards category; time_t hold_time; hold_time=time(NULL); I use this to intialize the time function ( displaying date and time to screen or writting ...

  1. #1
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765

    updating the clock ?

    time_t hold_time;
    hold_time=time(NULL);

    I use this to intialize the time function ( displaying date and time to screen or writting it to a file ).

    fprintf(File, ctime(&hold_time));

    I then use this to write it into a file.

    These functions are called on immediate program startup. If i use the ctime(&hold_time) function during the exit routine of the program, the new time isn't updated. How do i update it?

    The program isn't oppened again unless you phsyically type it at the comand prompt. Instead, program flow is bounced around inside the source code. Basically im trying to achieve a starting time of the program, then a "new" exiting time.
    The world is waiting. I must leave you now.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,671
    Do this at the start of the program
    hold_time=time(NULL);
    fprintf(File, ctime(&hold_time));


    Do this at the end of the program
    hold_time=time(NULL);
    fprintf(File, ctime(&hold_time));
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765

    thanks

    I believe i tried that way before hm...

    How does that work ?

    Understand what you learn instead of taking it for granted..

    - edited -

    To clear up any annoying confusion on this reply, that worked by the way...
    Last edited by Shadow; 09-22-2001 at 10:13 PM.
    The world is waiting. I must leave you now.

  4. #4
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    The first time you call time() you get the current system time into a variable. You then write it to a file as a string using ctime(). At the end of your program you again write that time to the file because you haven't updated it by calling time() again to get the new system time. Do you see now why you have to call time() again?
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  5. #5
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765

    yup

    I got it. My program is now up to 536 lines of code. I have a ways to go :/. Good thing im repeating lottsa stuff.
    The world is waiting. I must leave you now.

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,671
    > My program is now up to 536 lines of code
    If this is all one function, now is the time to explore the possibility of splitting the code up into functions.

    A rough rule of thumb - if you can't see a whole function on the screen at the same time, it's time to at least think about splitting it up.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Logical Error in Clock program
    By SVXX in forum C++ Programming
    Replies: 0
    Last Post: 05-10-2009, 12:12 AM
  2. Outside influences on clock cycles? (clock_t)
    By rsgysel in forum C Programming
    Replies: 4
    Last Post: 01-08-2009, 05:15 PM
  3. Clock Troubles
    By _Nate_ in forum C Programming
    Replies: 22
    Last Post: 06-19-2008, 05:15 AM
  4. clock program
    By bazzano in forum C Programming
    Replies: 3
    Last Post: 03-30-2007, 10:12 PM
  5. System clock
    By bazzano in forum C Programming
    Replies: 10
    Last Post: 03-27-2007, 10:37 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21