Category : C Source Code
Archive   : WTWG12B.ZIP
Filename : WVALDATE.C

 
Output of file : WVALDATE.C contained in archive : WTWG12B.ZIP
/* wvaldate.c
* validate a date string in form of mm/dd/yy or mm/dd/yyyy
*
* RETURNS: 0 if date is valid. nonzero otherwise.
* alters the date string by removing extra digits, sapces, etc...
* (never makes string longer than that provided)
*
*
*/
#include "wsys.h"

static int max_day[] = {0,31,29,31,30,31,30,31, 31,30,31,30,31};
#define NOT_LEAPYEAR(yy) ( ((yy)&3) || ( ((yy)/100)*100 ==(yy) ) )


int wval_date ( char *date )
{
int retcode =1;
unsigned int m=0,d=0,y=0;
char *ptr = date;

wdtparse ( &m, &ptr, '/' );
wdtparse ( &d, &ptr, '/' );
wdtparse ( &y, &ptr, '/' );

if ( ( (m>0) && (m<13) )
&& ( (d>0) && (d<=max_day[m]) )
&& ( (y>0) && (y<9999) )
&& (! ( (d==29) && (m==2) && NOT_LEAPYEAR(y) ) )
)
{
retcode = 0;
sprintf ( date, "%u/%u/%u", m,d,y);
}


return (retcode); /* wvdate ()*/
}

/*--------------- end of WVALDATE.C --------------------*/

  3 Responses to “Category : C Source Code
Archive   : WTWG12B.ZIP
Filename : WVALDATE.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/