G13 Answer


#include <stdio.h>
#include 

/* declare the enums */
typedef enum {mon, tue, wed, thr, fri, sat, sun} dayName;

typedef enum {jan, feb, mar, apr, may, jun, jly, aug, spt,
              oct, nov, dec} monthName;

/* declare the Date type */
typedef struct
{
  monthName month;
  int number;
  dayName day;
} Date;

/* function to print a Date */
void printDate( Date *date )
{
  char *dayStrings[] = { "Monday", "Tuesday", "Wednesday",
                         "Thursday", "Friday", "Saturday", "Sunday" };

  char *monthStrings[] = { "Jan", "Feb", "March", "April",
                         "May", "June", "July", "Aug",
                         "Sept", "Oct", "Nov", "Dec" };
                         
  printf( "%s, %s %2d\n", dayStrings[date->day], monthStrings[date->month],
      date->number );
}

/* function to set a Date */
void setDate( Date *date, int num, dayName name, monthName month )
{
  date->month = month;
  date->number = num;
  date->day = name;
}

int main(int argc, char *argv[])
{
  /* declare and initialize two Dates */
  Date birthday, duedate;

  /* set the dates */
  setDate( &birthday, 22, wed, feb );
  setDate( &duedate, 13, fri, aug );

  /* print values of both Dates */
  printDate( &birthday );
  printDate( &duedate );

  system("pause");
  return 0;
}

Comments: The translation between enum values and strings done in the print function uses the fact that the integer values given for enums automatically start with zero and increase by one for each following value. So

typedef enum {mon, tue, wed, thr, fri, sat, sun} dayName;

Associates 0 with mon, 1 with tue, and so on.