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
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
GBase 8s ESQL/C 编程指南 南大通用数据技术股份有限公司 - 891 - {
/* 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"); } 输出 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