I wrote and tested this under SCO Unix. Enjoy.
/*
A Time Example by C Williams
c.williams@swflug.org
for educational purposes only
built on SCO Unix (OpenServer 5.01) Aug 1, 2001
*/
/* our handy include files */
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <time.h>
/* some useful constants */
const static char *months[] = { "Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
};
const static char *days[] = { "Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
};
const static char *suffix[] = { "st",
"nd",
"rd",
"th"
};
/* prototype for local fucntion */
char *timeFunc(int yr, int dy);
int main(int argc, char **argv)
{
char kbBuffer[255]; // keyboard buffer
int year; // year
int days; // days
// get input from console and format it to an integer for year
printf("Please enter a year (Range = 1900+): "

;
fgets(kbBuffer,255,stdin);
year = atoi(kbBuffer);
// handle errors
if (year < 1900)
{
printf("Year out of range.\n"

;
return 1;
}
// get input from console and format it to an integer for days
printf("Please the number of days: "

;
fgets(kbBuffer,255,stdin);
days = atoi(kbBuffer);
// handle errors
if (days < 0)
{
printf("Day out of range.\n"

;
return 1;
}
// do output, using our timeFunc
printf("Output: %s\n", timeFunc(year,days));
return 0;
}
char *timeFunc(int yr, int dy)
{
char timestr[255]; // output string buffer
struct tm tmvar; // a tm structure we'll use
time_t tempvar, timevar; // some time_t variables we'll need
int weekday; // day of week
int month; // number of month
int day; // number of day
int lastdigit; // last digit of day
int sufxnum; // number of suffix to append
time(&tempvar); // get time & store in tempvar
tmvar = *localtime(&tempvar); // convert tempvar to a tm struct
tmvar.tm_mday = dy; // set the day
tmvar.tm_mon = 0; // reset month
tmvar.tm_year = yr - 1900; // set the year
tmvar.tm_yday = 0; // rest the day of year
timevar = mktime(&tmvar); // use mktime to update timevar
// handle errors
if (timevar == (time_t)(-1))
{
printf("Mktime() failed.\n"

;
exit (1);
}
tmvar = *localtime(&timevar); // convert timevar to a tm struct
// set our local integer variables
weekday = tmvar.tm_wday;
month = tmvar.tm_mon;
day = tmvar.tm_mday;
lastdigit = day - (10*(int)(day/10)); // get last digit
// we'll use do decide
// suffix "st", "nd", "rd", "st"
/* conditional to pick suffix for day of month */
switch (lastdigit)
{
case 1:
sufxnum = 0;
break;
case 2:
sufxnum = 1;
break;
case 3:
sufxnum = 2;
break;
default:
sufxnum = 3;
break;
}
/* now we'll format our output string with the data */
sprintf(timestr,"%s, %s %i-%s\0", days[weekday], months[month], day, suffix[sufxnum]);
return timestr;
}