< previous page page_92 next page >

Page 92
Listing 5.6 format_time_24()
/* fmttm24.c
   +-------------------------------------------+
   |   Copyright (C) 1995 by Lance W. Latham.  |
   |         All rights reserved.              |
   +-------------------------------------------+


   Formats a time of day to a string, assuming a 24-hour clock and a format
   of 'HH:MM:SS'. The separator is specifiable by input parameter.


   INPUTS:
   1. t, pointer to a TIME_INFO structure containing the time of day,
   2. sep, type char, the character to use for a separator.


   OUTPUTS:
   1. s, string containing the formatted time of day.


   NOTES:
   1. TIME_INFO times assume a 24-hour clock.
   2. This routine outputs a 24-hour clock.
   3. Use routine 'format_time_12' to output a 12-hour clock.
   4. This routine assumes that the output space assigned is large enough
      to contain the result. The longest string which can result from valid
      input is formatted as 'HH:MM:SS', so the minimum safe length is 9
      characters, including the terminating null.
*/


#include <stdio.h>
#include "scdtl_2.h"
void format_time_24 (struct TIME_INFO *t, char sep, char *s)
{
   sprintf (s, "%02d%c%02d%02d",
            t->hours, sep, t->minutes, sep, t->seconds);
      return;
}




 
< previous page page_92 next page >