/* ECP: FILEname=fig9_9.c */ /* 1*/ /*Fill In The tm_yday Field, As In mktime */ /* 2*/ int /* 3*/ MkYear( struct tm *TmStruct ) /* 4*/ { /* 5*/ static const int MonthDays[ ] = /* 6*/ { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; /* 7*/ static const int LeapMonthDays[ ] = /* 8*/ { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; /* 9*/ const int *MyMonthDays; /*10*/ int i; /*11*/ if( TmStruct != NULL ) /*12*/ { /*13*/ int Days = ( *TmStruct ).tm_mday; /*14*/ const int Month = ( *TmStruct ).tm_mon; /*15*/ const int Year = ( *TmStruct ).tm_year + 1900; /*16*/ MyMonthDays = IsLeap( Year ) ? LeapMonthDays : MonthDays; /*17*/ if( Month < 0 || Month > 11 || Days < 0 || /*18*/ Days > MyMonthDays[ Month ] ) /*19*/ return -1; /*20*/ for( i = 0; i < Month; i++ ) /*21*/ Days += MyMonthDays[ i ]; /*22*/ ( *TmStruct ).tm_yday = Days; /*23*/ return 0; /*24*/ } /*25*/ return -1; /*26*/ }