Figure 3: Routines to convert MMDDYYYY to/from (DDD)64

////////////////////////////////////////////////////////////////
//  Function: MMDDYYToDDDBased64
//
//  Description: Date converter. The number of days passed since
//  the starting date is converted to an octal number. This
//  number is split in 3 2-digits octal numbers. These numbers
//  are converted to decimals and serve as indices to
//  DigitsBasedOn64[] array. Overflow date for 3 char array is
//  09/23/2317.
//
//  Returns:  char * -- DDD.
////////////////////////////////////////////////////////////////
char *
MMDDYYToDDDBased64(int CCDigits, char *MMDDCCYYStartDate,
    char *MMDDYYDate,char *DDD) 
{
    char MMDDCCYYStartBuffer[9],MMDDCCYYBuffer[9],
         MMDDYYBuffer[7], DDDDDDBuffer[7],
         IndexBuffer[3]; 
    static char DDDBuffer[4];
    long DayCount;
    int Index1, Index2, Index3,Ind1, Ind2, Ind3, DDDDDDBufferLen;
    strcpy(MMDDCCYYStartBuffer, MMDDCCYYStartDate);
    memset (DDDDDDBuffer, '0', 6); // set all char to 0
    DDDDDDBuffer[6] = '\0';
    strcpy(MMDDYYBuffer, MMDDYYDate); 
    MMDDYYToMMDDCCYY(CCDigits, MMDDYYBuffer, MMDDCCYYBuffer); 
    DayCount = FindJulianDay(MMDDCCYYBuffer) - 
        FindJulianDay(MMDDCCYYStartBuffer);
    ltoa(DayCount, DDDDDDBuffer, 8); // convert to octal 
    DDDDDDBufferLen = strlen(DDDDDDBuffer);
    if(DDDDDDBufferLen==0 || DDDDDDBufferLen>6) { //invalid date
        DDD="";
        return""; 
    }    

    // Sets 0s in the beginning of a string
    // if it is shorter than 6 chars.
    CirculateChars(DDDDDDBuffer); 
    strncpy(IndexBuffer, DDDDDDBuffer, 2); 
    IndexBuffer[2] = '\0'; 
    Index1 = OctalToDecimal(IndexBuffer, &Ind1);
    memset(IndexBuffer, '0', 2);
    IndexBuffer[2] = '\0';
    strncpy(IndexBuffer, &DDDDDDBuffer[2], 2);
    Index2 = OctalToDecimal(IndexBuffer, &Ind2);
    memset(IndexBuffer, '0',2);
    IndexBuffer[2] = '\0';
    strncpy(IndexBuffer, &DDDDDDBuffer[4], 2);
    Index3 = OctalToDecimal(IndexBuffer, &Ind3);
    DDDBuffer[0] = DigitsBasedOn64[Index1];
    DDDBuffer[1] = DigitsBasedOn64[Index2];
    DDDBuffer[2] = DigitsBasedOn64[Index3];
    DDDBuffer[3] = '\0';
    strcpy(DDD, DDDBuffer);
    return DDDBuffer;
}

/* End of File */