home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / c / cuj9301.zip / 1101118A < prev    next >
Text File  |  1992-11-03  |  954b  |  39 lines

  1. /* tdate.c: Test date_interval() */
  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 = date_interval(&d1, &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> 10/6/92
  35. years: 41, months: 0, days: 5
  36. */
  37.  
  38. /* End of File */
  39.