home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_11_02 / 1102125a < prev    next >
Text File  |  1992-12-10  |  923b  |  39 lines

  1. // tdate.cpp: Test the Date class
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include "date.h"
  6.  
  7. main()
  8. {
  9.     Date d1, d2, *result;
  10.     int nargs;
  11.     
  12.     // Read in two dates - assume 1st precedes 2nd
  13.     fputs("Enter a date, MM/DD/YY> ",stderr);
  14.     nargs = scanf("%d/%d/%d%*c", &d1.month,
  15.       &d1.day, &d1.year);
  16.     if (nargs != 3)
  17.         return EXIT_FAILURE;
  18.         
  19.     fputs("Enter a later date, MM/DD/YY> ",stderr);
  20.     nargs = scanf("%d/%d/%d%*c", &d2.month,
  21.       &d2.day, &d2.year);
  22.     if (nargs != 3)
  23.         return EXIT_FAILURE;
  24.     
  25.     // Compute interval in years, months, and days
  26.     result = d1.interval(d2);
  27.     printf("years: %d, months: %d, days: %d\n",
  28.         result->year, result->month, result->day);
  29.     return EXIT_SUCCESS;
  30. }
  31.  
  32. /* Sample Execution:
  33. Enter a date, MM/DD/YY> 10/1/51
  34. Enter a later date, MM/DD/YY> 11/14/92
  35. years: 41, months: 1, days: 13
  36. */
  37.  
  38.  
  39.