#ifndef _ValiDate_CPP_ #define _ValiDate_CPP_ // INCLUDES #include #include #include #include // NAME: ValiDate.CPP // TYPE: C++ SOURCE FILE // SYNOPSIS: // function validates a date input in the format DD/MM/YY // function returns bool and accepts as an argument // a pointer to the string to a string holding the date to validate // EXAMPLES: // BUGS: // SEE ALSO: //--------------------------------------------------------------------------- // Function Prototype to place in header bool IsValiDate(const char* str); //--------------------------------------------------------------------------- /* void main() { char input[9] =" ";//{ "28/2/2000" }; if( IsValiDate( input) ) cout<< "\nDate is valid"; else cout<< "\nDate is not valid"; cout<<"\nPress any key to exit... "; while( !cin.get() ) ; } */ ////////////////////// // Function: bool IsValiDate(const char* str) // Description: // Returns: // Argument1 ///////// bool IsValiDate(const char* str) { // checks for empty string if( !isdigit( str[0] ) ) return false; // declarations char s1[3]; // define a local string char* dayStr =s1; // assign a pointer to the string char s2[3]; char* monthStr = s2; char s3[5]; char* yearStr = s3; // parse while( *str != '/' ) // digits b4 '/' *dayStr++ = *str++; *dayStr++ ='\0'; // terminate ++str; // skip '/' while( *str != '/' ) *monthStr++ = *str++; *monthStr++ ='\0'; ++str; while( *str ) *yearStr++ = *str++; *yearStr++ ='\0'; // DayTy day = static_cast( atoi( s1 ) ); MonthTy month = static_cast( atoi( s2 ) ); YearTy year = static_cast< YearTy>( atoi( s3 ) ); // construct a TDate object to validate with TDate date(day, month, year); if( date.IsValid() ) return true; return false; } #endif // _ValiDate_CPP_