Thread: Printing Current TIME

  1. #1
    Registered User
    Join Date
    Jun 2013
    Posts
    20

    Printing Current TIME

    Hi ,

    Its a code in module of my program, where I need to print current time (HH:MM:SS) at regular intervals. I excluded other code for understanding.


    Code:
    #include<time.h>
    #include<stdio.h>
    //#include<windows.h>
    
    void delay(unsigned int t){        // loop for some delay.
        int k;
        while(t--)
            for(k=0;k<1275;k++);
    }
    
    void main(){
    
        printf("Time: %s",__TIME__);
        delay(10000);  // Sleep(10000);
        printf("\nTime: %s",__TIME__);
    
    }

    But when I am running this code I expect this to print difference in time due to delay.


    Printing Current TIME-capture-jpg

    But it doesn't enter the delay loop, why ?


    Regards,
    Raady.

  2. #2
    11DE784A SirPrattlepod's Avatar
    Join Date
    Aug 2013
    Posts
    485
    __TIME__ is the time that the preprocessor is run (i.e. the time that that bit of code was compiled).

  3. #3
    11DE784A SirPrattlepod's Avatar
    Join Date
    Aug 2013
    Posts
    485
    Also, don't use void main(void)... it's not standard C.

    The loop

    Code:
        while(t--)
            for(k=0;k<1275;k++);
    is also likely to be optimised away by the compiler.

  4. #4
    Registered User
    Join Date
    Jun 2013
    Posts
    20
    then how can I print time from system at regular intervals ?

  5. #5
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    A good faq for main.
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  6. #6
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    look at the time() function.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Printing current system time in C++
    By newbie123 in forum C++ Programming
    Replies: 2
    Last Post: 08-27-2010, 07:00 AM
  2. Replies: 7
    Last Post: 11-21-2009, 01:02 AM
  3. Converting Zulu Time to Current Time
    By Caldus in forum C++ Programming
    Replies: 3
    Last Post: 06-08-2006, 08:54 PM
  4. current time
    By lithium in forum C Programming
    Replies: 3
    Last Post: 01-26-2003, 05:42 PM
  5. Please help with current time in c++
    By Agnesa in forum C++ Programming
    Replies: 2
    Last Post: 10-30-2002, 08:10 AM

Tags for this Thread