Thread: time

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    25

    time

    this prints the time

    Code:
     
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    int main(void)
    {
      time_t now;
      time(&now);
    
      printf("%s", ctime(&now));
    
      return EXIT_SUCCESS;
    }
    but it doesnt keep up. So i would like some hints on how to keep the time going. if all possible.

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    131
    Continuos loop were you check and update(display)....

  3. #3
    Unregistered User
    Join Date
    Sep 2005
    Location
    Antarctica
    Posts
    341
    maybe something like this:

    Code:
    time_t now;
    time(&now);
    
    while(true)
    {
        time(&now);
        char *sz = ctime(&now);
    
        sz[strlen(sz) - 1] = 0; /* this gets rid of the \n */
        printf("\r%s         ", sz);
    }

  4. #4
    Registered User
    Join Date
    Sep 2005
    Posts
    25
    sz[strlen(sz) - 1] = 0 what does this do? I tried it and it says i need to declare it. and without me really knowing what it does or is, its not gonna help me learn ..chow.

  5. #5
    Registered User
    Join Date
    Sep 2005
    Posts
    25
    haha.. i got it.. thanks..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to get current time
    By tsubasa in forum C Programming
    Replies: 3
    Last Post: 05-01-2009, 02:03 AM
  2. Replies: 11
    Last Post: 03-29-2009, 12:27 PM
  3. Help with assignment!
    By RVDFan85 in forum C++ Programming
    Replies: 12
    Last Post: 12-03-2006, 12:46 AM
  4. calculating user time and time elapsed
    By Neildadon in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2003, 06:00 PM
  5. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 10:12 PM