home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 328_02 / wvaltime.c < prev   
C/C++ Source or Header  |  1991-03-17  |  792b  |  34 lines

  1. /* wvaltime.c
  2.  *    validate a time string in form of hh:mm:ss or hh:mm
  3.  *
  4.  *    RETURNS: 0 if time is valid. nonzero otherwise.
  5.  *            alters the time string by removing extra digits, sapces, etc...
  6.  *
  7.  *        adds missing 'ss' field if not provided originally.
  8.  *            (ie: buffer must be at least 9 bytes.)
  9.  *
  10.  */
  11. #include "wsys.h"
  12.  
  13.  
  14. int wval_time ( char *time )
  15.     {
  16.     int retcode =1;
  17.     unsigned int h=100,m=100, s=0;    /* NOTE: h,m req'd by default setting */
  18.     char *ptr = time;
  19.         
  20.     wdtparse ( &h, &ptr, ':' );
  21.     wdtparse ( &m, &ptr, ':' );
  22.     wdtparse ( &s, &ptr, ':' );
  23.     
  24.     if     (   h<24  && m<60 && s<60 )   
  25.         {
  26.         retcode = 0;
  27.         sprintf ( time, "%u:%u:%2.2u", h,m,s);
  28.         }
  29.     
  30.  
  31.     return (retcode);        /* wval_time ()*/
  32.     }
  33.     
  34. /*--------------- end of WVALTIME.C --------------------*/