Y2K Millennium Compliance - University of Delaware


C Program test5.c


/**           Program test5.c
 
  Program test5.c reads in a date string, parses the string
and prints out the month, day and year.  This string can be 
of any format as defined the templated file, "timetemplate.txt",
which contains entries such as 

          %B %d %y, %H:%M:%S
          %B %d %y  %H:%M:%S
          %B %d %Y, %H:%M:%S
          %B %d %Y  %H:%M:%S
          %B %d %y, %I %p
          %B %d %y  %I %p
          %B %d %Y, %I %p
          %B %d %Y  %I %p
          %B %d %y, %I:%M %p
          %B %d %y  %I:%M %p
          %B %d %Y, %I:%M %p
          %B %d %Y  %I:%M %p
          %B %d %y, %I:%M:%S %p
          %B %d %y  %I:%M:%S %p
          %B %d %Y, %I:%M:%S %p
          %B %d %Y  %I:%M:%S %p
          %m/%d/%y %I %p
	  %m/%d/%Y %I %p
          %m/%d/%y %I:%M %p
          %m/%d/%Y %I:%M %p
          %m/%d/%y %I:%M:%S %p
          %m/%d/%Y %I:%M:%S %p
          %m/%d/%y %T
	  %m/%d/%Y %T
 
(See the man pages for details of the getdate routine as well as
the meaning of the formats shown above).
 
  Example:

	January 1 1990 11 pm
	1/1/88 20:14:33
 
**/
#include 
#include 

main()
{
/* Define pointers time1 and time2 that point to the structure tm */
  struct tm *time1,*time2;
char dt[30],dtin[30];

/* Need to allocate storage for time2 */
  time2=(struct tm *)malloc(sizeof(struct tm)); 
  printf("\n");

  printf("Enter a date using either a 2 or 4 digit year and a time\n");
  gets(dtin);
  printf("\n");
  printf("INPUT: \n");
  printf("\n");
  printf("The date entered  is %s\n",dtin,"\n");   
  strcpy(dt,dtin);
  time2=getdate(dt);  
  printf("\n");
  printf("OUTPUT: \n");
  printf("\n");
  printf("The month is %d\n",time2->tm_mon + 1);
  printf("The day is %d\n", time2->tm_mday);
  printf("The year is %d\n",time2->tm_year);
  printf("The hour is %d\n", time2->tm_hour);
  printf("\n"); 

  free(time2); 
}