/*****
                              maketime()

      This function formats the system time into the string passed to the
   function using interrupt 0x21. The function allows for a 12- or 24-hour
   clock. If a 12-hour clock is used, the input string must allow for 3
   more characters to hold the time.

   Argument list:    char *buff     pointer to a character array for the
                                    time
                     int sep        the character to be used to space the
                                    time fields
                     int mode       0 if a 12-hour clock is wanted,
                                    nonzero for a 24-hour clock.

   Return value:     void

*****/

#include <stdio.h>
#include <dos.h>
#include <string.h>

void maketime(char *buff, int sep, int mode)
{
   char time[3];
   union REGS ireg;

   ireg.h.ah = 0x2c;
   intdos(&ireg, &ireg);

   time[0] = '\0';
   if (mode == 0) {
      if (ireg.h.ch > 12) {
         ireg.h.ch -= 12;
         strcpy(time, "PM");
      } else {
         strcpy(time, "AM");
      }
   }
   sprintf(buff, "%02d%c%02d%c%02d %s", ireg.h.ch, sep, ireg.h.cl,
                 sep, ireg.h.dh, time);
}
