C Language Development Kit/Functions/CheckDate

From OptiWiki

Jump to: navigation, search
Description Checks if the date structure passed to the function holds a valid date. For

instance, if you specify a date of 29 February 2002, the function will return FALSE, because February only holds 28 days in a non leap year.

Syntax
int checkdate(struct date * datep);
Arguments
struct date * datep
Pointer to the date structure that is to be checked.
Returns
OK When the date is valid.
ERROR When the date is invalid.
Example
#include "lib.h"
#include <stdio.h>
 
void main( void )
{
    struct date d;
 
    d.da_year = 2002;
    d.da_mon = 2;
    while( 1 )
    {
        d.da_day = 29; // not 29 days in non leap year
        if( checkdate( &d ) == OK )
            printf("\fDate ok!!\n");
        else
            printf("\fIllegal Date!!");
        while( !kbhit() )
            idle();
        resetkey();
 
        d.da_day = 28;
        if( checkdate( &d ) == OK )
            printf("\fDate ok!!\n");
        else
            printf("\fIllegal Date!!");
        while( !kbhit() )
            idle();
        resetkey();
    }
}


Views
Personal tools