Figure 1: Two-year date compression function

#include <string.h>
#include <ctype.h>

/* These two array declarations allow
   for portability, and therefore allow
   these functions to not rely on the
   ascii character set. */

const char letters[] =
    "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const char digits[] = "0123456789";

/* Compresses the year into two
   characters and stores it into
   compressed */

void toCompressed( int year, char* compressed )
{
    int century = year / 100;
    year = year - century * 100;
    int decade = year / 10;

    /* If the century is the 20th (1900s) then just store the
       last two digits in a character format. */
    if( century == 19 )
    {
        compressed[0] = digits[ decade ];
        compressed[1] = digits[ year - decade * 10 ];
    }
    /* Else if the century is the 21st(2000s) then change the
       first digit to its corresponding letter and append the
       last digit after converting it to a letter. */
    else if( century == 20 )
    {
        compressed[0] = letters[ decade ];
        compressed[1] = digits [ year - decade * 10 ];
    }
    /* Else if the century is the 22nd(2100s) then change the
       first digit to the letter ten places higher than the 21st
       century's corresponding letter and append the last
       digit. */
    else if( century == 21 )
    {
        compressed[0] = letters[ decade + 10 ];
        compressed[1] = digits [ year - decade * 10 ];
    }
}
/* End of File */