home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 463.lha / Date_routines / maketime.c < prev    next >
C/C++ Source or Header  |  1991-01-04  |  1KB  |  44 lines

  1. /*****
  2.                               maketime()
  3.  
  4.       This function formats the system time into the string passed to the
  5.    function using interrupt 0x21. The function allows for a 12- or 24-hour
  6.    clock. If a 12-hour clock is used, the input string must allow for 3
  7.    more characters to hold the time.
  8.  
  9.    Argument list:    char *buff     pointer to a character array for the
  10.                                     time
  11.                      int sep        the character to be used to space the
  12.                                     time fields
  13.                      int mode       0 if a 12-hour clock is wanted,
  14.                                     nonzero for a 24-hour clock.
  15.  
  16.    Return value:     void
  17.  
  18. *****/
  19.  
  20. #include <stdio.h>
  21. #include <dos.h>
  22. #include <string.h>
  23.  
  24. void maketime(char *buff, int sep, int mode)
  25. {
  26.    char time[3];
  27.    union REGS ireg;
  28.  
  29.    ireg.h.ah = 0x2c;
  30.    intdos(&ireg, &ireg);
  31.  
  32.    time[0] = '\0';
  33.    if (mode == 0) {
  34.       if (ireg.h.ch > 12) {
  35.          ireg.h.ch -= 12;
  36.          strcpy(time, "PM");
  37.       } else {
  38.          strcpy(time, "AM");
  39.       }
  40.    }
  41.    sprintf(buff, "%02d%c%02d%c%02d %s", ireg.h.ch, sep, ireg.h.cl,
  42.                  sep, ireg.h.dh, time);
  43. }
  44.