home *** CD-ROM | disk | FTP | other *** search
/ C by Discovery (4th Edition) / C_By_Discovery_4th_Edition.tar / C_By_Discovery_4th_Edition / _DISK_ / ch11 / timex.c < prev   
C/C++ Source or Header  |  2005-06-16  |  1KB  |  38 lines

  1. /*               timex.c
  2.  *
  3.  *   Synopsis  - Displays today's time and date, the date
  4.  *               tomorrow, and the processor time used by
  5.  *               the program.
  6.  *
  7.  *   Objective - To introduce the time and date library
  8.  *               functions.
  9.  */
  10.  
  11. /* Include Files */
  12. #include <time.h>                                 /* Note 1 */
  13. #include <stdio.h>
  14.  
  15. int main( void )
  16. {
  17.      time_t t1;                                   /* Note 2 */
  18.      struct tm *tptr;
  19.      clock_t ticks;                               /* Note 2 */
  20.      char *s;
  21.                                                   /* Note 3 */
  22.      if ( ( t1 = time(( time_t * ) 0 )) != ( time_t )-1 ) {
  23.           s = ctime( &t1 );                       /* Note 4 */
  24.           printf( "currentdate is %s", s );
  25.           tptr = localtime( &t1 );                /* Note 5 */
  26.                                                   /* Note 6 */
  27.           printf( "Tomorrow is %d/%d/02%d.\n", tptr->tm_mon+1, tptr->tm_mday+1, tptr->tm_year-100 );
  28.      }
  29.      else
  30.           printf( "Error with the time() function\n" );
  31.                                                   /* Note 7 */
  32.      if (( ticks = clock() ) != ( clock_t )-1 )
  33.           printf( "%4.2f seconds used by the processor.\n", (double)ticks/CLK_TCK );  /* Note 8 */
  34.      else
  35.           printf( "Error with the clock() function\n" );
  36.      return 0;
  37. }
  38.