/* Program 9-6

   Program to illustrate arrays of structures */

struct time
 {
  int hour;
  int min;
  int sec;
 }
 
struct time time_update(struct time);

main ()
 {
  static struct time test_times[5] = { { 11, 59, 59 },
				       { 12, 0, 0 },
				       { 1, 29, 59 },
				       { 23, 59, 59 },
				       { 19, 12, 27 } };

  int i;

  for ( i = 0; i < 5; ++i )
   {
    printf ("Time is %02d:%02d:%02d", test_times[i].hour,
				      test_times[i].min,
				      test_times[i].sec);

    test_times[i] = time_update (test_times[i]);

    printf (" ...one second later it's %02d:%02d:%02d\n", test_times[i].hour,
							  test_times[i].min,
							  test_times[i].sec);

   }
 }

/* Function to update the time by one second */

struct time time_update(struct time now)
 {
  struct time new_time;
  new_time = now;
  ++new_time.sec;

  if ( new_time.sec == 60 )
   {
    new_time.sec = 0;
    ++new_time.min;

    if ( new_time.min == 60 )
     {
      new_time.min = 0;
      ++new_time.hour;

      if ( new_time.hour == 24 )
       new_time.hour = 0;
     }
   }

  return (new_time);
 }


/* Program Output

Time is 11:59:59 ...one second later it's 12:00:00
Time is 12:00:00 ...one second later it's 12:00:01
Time is 01:29:59 ...one second later it's 01:30:00
Time is 23:59:59 ...one second later it's 00:00:00
Time is 19:12:27 ...one second later it's 19:12:28

*/





