introducing actual time in a C program

This is a discussion on introducing actual time in a C program within the C Programming forums, part of the General Programming Boards category; Hi everyone. wel l i wanted to know if it was possible to assign the date of today[ date stored ...

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    39

    Smile introducing actual time in a C program

    Hi everyone. wel l i wanted to know if it was possible to assign the date of today[ date stored in the os time system] to a particular variable and then i will be using that date to know when a particular line of text has been input in of of my data file..



    or simply is there a function for this?? Else if this is not possible then ill have to ask the user to enter the date during program execution, but this seems a bit lengthy.. please do suggest.. thnks in advance.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    There are a bunch of functions to do that in "time.h". Ideally, you want to store the content of a "struct tm", which is a standard format struct. Several functions return a "time_t" type, which is implementation dependent, so if you store that value, it will not work right if you move to another system.

    Here are some references to the basic "time()" function call, which returns the current time in a time_t type - you then have to convert that with for example localtime() or gmtime()
    http://www.hmug.org/man/3/time.php
    http://www.hmug.org/man/3/ctime.php (gives localtime and friends)


    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Aug 2007
    Posts
    39
    thanks i will try it... also is there somewhere i can find the different functions that i can use with a particular file header?? such a <stdio.h> <math.h>..

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    There should be some reference books and web-sites. www.cppreference.com does it for C++ (but includes the C standard libraries too, although stdio.h would be called cstdio - it's the same thing, just converted so that it works with C++ includes really).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Aug 2007
    Posts
    39
    thankss.. soo nice of ya..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Check if a program creates prt scrs
    By Livijn in forum C# Programming
    Replies: 6
    Last Post: 09-11-2008, 05:43 AM
  2. How to time how long a program takes to run?
    By advancedk in forum C Programming
    Replies: 2
    Last Post: 08-18-2008, 07:50 PM
  3. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  4. Read and set\change system time
    By Hexxx in forum C++ Programming
    Replies: 9
    Last Post: 01-02-2006, 06:11 AM
  5. compile time error in example program
    By dragonlady in forum Windows Programming
    Replies: 3
    Last Post: 01-01-2006, 12:44 PM

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