Exercise (5-9):
Rewrite the routines day_of_year
with pointers instead of indexing.
static char daytab[2][13] = {
{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
{0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
};
/* day_of_year: set day of year from month and day */
int day_of_year(int year, int month, int day)
{
int i, leap;
leap = (year%4 == 0) && (year%100 != 0) || (year%400 == 0);
for (i = 1; i < month; i++)
{
day += daytab[leap][i];
}
return day;
}
I may just be tired and not thinking, but how does one actually create a multidimensional array with pointers?
I could probably figure out the rest of the function, but I can't get the syntax right.
Thanks!