#include #include #include #include // itoa() TDate StringToDate( char* ); /* // Driver void main() { char str[] ={"27/02/1999"}; cout<< StringToDate(str); cout<<"\nPress any key to exit... "; while( !cin.get() ) ; }*/ ////////////////////// // Function: char* DateToString(TDate&) // // Description: constructs a string from the members // of a TDate // Returns: pointer to a string // Argument1 reference to DateStruct ///////// TDate StringToDate( char* str ) { // create strings to put values in char s1[3]; char* dayStr =s1; char s2[3]; char* monthStr =s2; char s3[5]; char* yearStr =s3; // parse if( ! (*str) ) str++; // skip leading 0 while( *str != '/' ) // digits b4 '/' *dayStr++ = *str++; *dayStr++ ='\0'; // add terminating character ++str; // skip '/' if( ! (*str) ) str++; // skip leading 0 while( *str != '/' ) *monthStr++ = *str++; *monthStr++ ='\0'; str++; while( *str != '\0' ) *yearStr++ = *str++; *yearStr++ ='\0'; TDate d( atoi(s1), atoi(s2), atoi(s3) ); return d; }