training

Code I wrote during training
git clone git://git.bitsmanent.org/training
Log | Files | Refs | README

ex-6.4.c (619B)


      1 /*
      2  * Advanced Programming in the UNIX(r) Environment
      3  *
      4  * Exercise 6.4
      5  *
      6  * Sample output: ven feb 15 16:30:43 CET 2008
      7 */
      8 
      9 
     10 #include <stdio.h>
     11 #include <stdlib.h>
     12 #include <time.h>
     13 
     14 #define TMBUFSZ 64
     15 
     16 int
     17 main(void)
     18 {
     19    struct tm *tm_t;
     20    char tmbuf[TMBUFSZ];
     21    time_t tmcal;
     22 
     23    tmcal = time(NULL);
     24 
     25    /* Get the broken-down local time */
     26    if( (tm_t = localtime(&tmcal)) == NULL ) {
     27       perror("localtime");
     28       return EXIT_FAILURE;
     29    }
     30 
     31    /* Generate the output string */
     32    strftime(tmbuf, TMBUFSZ, "%a %b %d %X %Z %Y", tm_t);
     33 
     34    printf("%s\n", tmbuf);
     35 
     36    return EXIT_SUCCESS;
     37 } /* eof main() */
     38