I need this code to do the task below. Can anyone help me get it doing that? thanx in advance.

TASK:

write a C program calen that displays calendar details about specified dates. The program reads commands from standard input that specify what calendar information to display. Commands can be of several forms:

If the command is of the form "d dd mm yyyy", where dd, mm, and yyyy are integers representing the day, month, and year, the program prints a line reporting the weekday for the given date:
d 1 1 2000
1 January 2000 is a Saturday
If the year, month, or day are omitted, the program substitutes information for the current date. Thus (assuming the current date is 24 August 2002):
d 31 12
31 December 2002 is a Tuesday

d 15
15 August 2002 is a Thursday

d
24 August 2002 is a Saturday

If the command is of the form "m mm yyyy", the program
prints a calendar for the given month:

m 12 1999
December 1999
S M Tu W Th F S
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31


Note that the display consists of 6 "week" lines, even if (as in
this example), the final week (or 2 weeks for February in some
years) is entirely blank. If the year or month are omitted, the
program uses information for the current date instead.

If the command is of the form "y yyyy", the program
prints a calendar for the entire given year:

y 1998
1998

Jan Feb Mar
S M Tu W Th F S S M Tu W Th F S S M Tu W Th F S
1 2 3 1 2 3 4 5 6 7 1 2 3 4 5 6 7
4 5 6 7 8 9 10 8 9 10 11 12 13 14 8 9 10 11 12 13 14
11 12 13 14 15 16 17 15 16 17 18 19 20 21 15 16 17 18 19 20 21
18 19 20 21 22 23 24 22 23 24 25 26 27 28 22 23 24 25 26 27 28
25 26 27 28 29 30 31 29 30 31

Apr May Jun
S M Tu W Th F S S M Tu W Th F S S M Tu W Th F S

The months are arranged in 4 rows (with the first row displaying
calendars for Jan, Feb, and Mar), and the months in a row
separated by 3 blank spaces. There should be no blank line
between rows unless (as here) the last week of all months happens
to be blank. Note the alignment of the day-of-the week letters,
the month names, and the year. If the year is omitted, the
current year is used instead.

If the command begins with a digit, then "day" format is
assumed. Thus 26 1 2000 is equivalent to d 26 1
2000.

If the command begins with any other character, the program
prints an error message:

f 24 8 2002
Unknown command: f

_______________________________________________

CODE:

#include <sys/time.h>
#include <time.h>
#include "date.h"
#include <stdio.h>

/* true for leap years */


int leap_year (int year) {

return year % 400 == 0 || year % 100 != 0 && year % 4 == 0;
}

/* the number of days in month of year */


int days_in_month (int month, int year) {

switch (month) {
case 9: case 4: case 6: case 11:
return 30;
case 2:
return leap_year(year) ? 29 : 28;
default:
return 31;
}
}

/* the weekday (0 = Sunday) of a given date
accurate for dates in the Gregorian calendar
which began on 14 September 1752 */


int week_day (int day, int month, int year) {

int d = 14; /* The modern calendar began on 14 ... */
int m = 9; /* ... September ... */
int y = 1752; /* ... 1752 ... */
int n = 4; /* ... which was a Thursday */

while (year > y || month > m || day > d) {
n++;
day--;
if (day < 1) { month--; day = days_in_month(month, year); }
if (month < 1) { year--; month = 12; }
}
return n % 7;
}

struct timeval tv;


int current_day () {

gettimeofday(&tv, 0);
return localtime(&tv.tv_sec)->tm_mday;
}


int current_month () {

gettimeofday(&tv, 0);
return localtime(&tv.tv_sec)->tm_mon + 1;
}


int current_year () {

gettimeofday(&tv, 0);
return localtime(&tv.tv_sec)->tm_year + 1900;
}



void do_day ( char *cmd ) {


int day, month, year;
int res;
res = sscanf( cmd, "%*c %d %d %d", &day, &month, &year );
if ( res == 3 ) {
printf( "Calculate for day=%d, month=%d, year=%d\n", day, month, year );
}
else {
printf( "Bad day command parameters\n" );
}
}


void do_month ( char *cmd ) {


int month, year;
int res;
res = sscanf( cmd, "%*c %d %d", &month, &year );
if ( res == 2 ) {
printf( "Calculate for month=%d, year=%d\n", month, year );
}
else {
printf( "Bad month command parameters\n" );
}}



void do_year ( char *cmd ) {


int year;
int res;
res = sscanf( cmd, "%*c %d", &year );
if ( res == 3 ) {
printf( "Calculate for year=%d\n", year );
}
else {
printf( "Bad year command parameters\n" );
}
}



int first_day_of_month ( int year, int month ) {


struct tm t = { 0 };
struct tm *tp;
time_t now;
t.tm_mday = 1;
t.tm_mon = month-1;
t.tm_year = year-1900;
now = mktime(&t);
tp = localtime(&now);
return tp->tm_wday;
}



int main ( ) {


char buff[BUFSIZ];
while ( fgets( buff, BUFSIZ, stdin ) != NULL ) {
switch ( buff[0] ) {
case 'd':
do_day ( buff );
break;
case 'm':
do_month ( buff );
break;
case 'y': do_year ( buff );
break;
default:
printf( "Unknown command %c\n", buff[0] );
break;
}
}
{
int i;
for ( i = 1 ; i <= 12 ; i++ ) {
int day = first_day_of_month( 2002, i );
printf( "First day of %d/%d is %d\n", 2002, i, day );
}
}
return 0;
}