The rleapyear() function
The rleapyear() function returns 1 (TRUE) when the argument that is passed to it is a leap year and 0 (FALSE) when it is not.
Syntax
mint rleapyear(year)
mint year;
- year
- An integer.
Usage
The argument year must be the year component of a date and not the date itself. You must express the year in full form (2007) and not abbreviated form (07).
Return codes
- 1
- The year is a leap year.
- 0
- The year is not a leap year.
Example
The demo directory
contains this sample program in the rleapyear.ec file.
/*
* rleapyear.ec *
The following program accepts a date entered from the console
and stores this date into an int4, which stores the date in
an internal format. It then converts the internal format into an array of
three short integers that contain the month, day, and year portions of the
date. It then tests the year value to see if the year is a leap year.
*/
#include <stdio.h>
main()
{
int4 i_date;
mint errnum;
short mdy_array[3];
char date[20];
mint x;
static char fmtstr[9] = "mmddyyyy";
printf("RLEAPYEAR Sample Program running.\n\n");
/* Allow user to enter a date */
printf("Enter a date as a single string, month.day.year\n");
gets(date);
printf("\nThe date string is %s.\n", date);
/* Put entered date in internal format */
if (x = rdefmtdate(&i_date, fmtstr, date))
printf("Error %d on rdefmtdate conversion\n", x);
else
{
/* Convert internal format into a MDY array */
if ((errnum = rjulmdy(i_date, mdy_array)) == 0)
{
/* Check if it is a leap year */
if (rleapyear(mdy_array[2]))
printf("%d is a leap year\n", mdy_array[2]);
else
printf("%d is not a leap year\n", mdy_array[2]);
}
else
printf("rjulmdy() call failed with error %d", errnum);
}
printf("\nRLEAPYEAR Sample Program over.\n\n");
}
Output
RLEAPYEAR Sample ESQL Program running.
Enter a date as a single string, month.day.year
10.12.07
The date string is 10.12.07.
2007 is not a leap year
RLEAPYEAR Sample Program over.