Thread: Help with time.h functions please.

  1. #1
    Registered User Ifurita.'s Avatar
    Join Date
    May 2003

    Question Help with time.h functions please.

    Hello and good morning, I've been having alot of trouble recently with time.h functions using Dev-C++. I have learned how to get the time to display finally, but I would like it to be formatted in a since of hour:minute, if possible.

    The program is to help keep time in a billard room for the pool tables. My C++ Knowledge is limited, due to a poor teacher in High School who only checked the result of our programs and rarely understood the code.

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User
    Join Date
    Apr 2003
    #include <ctime>

    time_t secs = 0;

    This is from MSDN:

    char *ctime( const time_t *timer );
    time_t time( time_t *timer );
    time_t long integer

    Apparently, the time() function will store the return value at the "timer" location.

    For some reason, this compiles but won't work even though the parameters appear to match the function declarations:

    time_t* secs = 0;
    Last edited by 7stud; 05-19-2003 at 01:52 PM.

  4. #4
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Ontario, Canada
    #include <iostream>
    #include <ctime>
    int main( void ) {
      time_t curTime = time( NULL );
      tm *tmstruct = localtime( &curTime );
      char buffer[ 256 ];
      strftime( buffer, 256, "%I:%M %p", tmstruct ); // 12 hour time
      strftime( buffer, 256, "%H:%M", tmstruct ); // 24 hour time
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  5. #5
    Registered User Ifurita.'s Avatar
    Join Date
    May 2003


    Most appreciated, thank you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Functions and Classes - What did I do wrong?
    By redmage in forum C++ Programming
    Replies: 5
    Last Post: 04-11-2005, 11:50 AM
  2. calling functions within functions
    By edd1986 in forum C Programming
    Replies: 3
    Last Post: 03-29-2005, 03:35 AM
  3. Factory Functions HOWTO
    By GuardianDevil in forum Windows Programming
    Replies: 1
    Last Post: 05-01-2004, 01:41 PM
  4. Shell functions on Win XP
    By geek@02 in forum Windows Programming
    Replies: 6
    Last Post: 04-19-2004, 05:39 AM
  5. functions - please help!!!!
    By linkies in forum C Programming
    Replies: 1
    Last Post: 08-21-2002, 07:53 AM