@@ -76,9 +76,8 @@ int month_day(const int year, int yearday, int *const pmonth, int *const pday) {
76
76
77
77
int main () {
78
78
int year , month , day , yearday ;
79
- int * pday , * pmonth ;
80
- pday = malloc (sizeof (int ));
81
- pmonth = malloc (sizeof (int ));
79
+ int pday = 0 ;
80
+ int pmonth = 0 ;
82
81
83
82
// daytab is an array of pointers to arrays of chars; these could now
84
83
// be of different lengths as opposed to a "true" array of arrays
@@ -92,29 +91,29 @@ int main() {
92
91
month = 6 ;
93
92
day = 12 ;
94
93
yearday = day_of_year (year , month , day );
95
- month_day (year , yearday , pmonth , pday );
94
+ month_day (year , yearday , & pmonth , & pday );
96
95
printf ("%d/%d/%d was day #%d.\n" , month , day , year , yearday );
97
- printf ("day %d of year %d was %d/%d.\n\n" , yearday , year , * pmonth , * pday );
96
+ printf ("day %d of year %d was %d/%d.\n\n" , yearday , year , pmonth , pday );
98
97
99
98
// Invalid day
100
99
day = 2000 ;
101
100
yearday = day_of_year (year , month , day );
102
- month_day (year , yearday , pmonth , pday );
101
+ month_day (year , yearday , & pmonth , & pday );
103
102
printf ("%d/%d/%d was day #%d.\n" , month , day , year , yearday );
104
- printf ("day %d of year %d was %d/%d.\n\n" , yearday , year , * pmonth , * pday );
103
+ printf ("day %d of year %d was %d/%d.\n\n" , yearday , year , pmonth , pday );
105
104
106
105
// Invalid month
107
106
month = 87 ;
108
107
yearday = day_of_year (year , month , day );
109
- month_day (year , yearday , pmonth , pday );
108
+ month_day (year , yearday , & pmonth , & pday );
110
109
printf ("%d/%d/%d was day #%d.\n" , month , day , year , yearday );
111
- printf ("day %d of year %d was %d/%d.\n\n" , yearday , year , * pmonth , * pday );
110
+ printf ("day %d of year %d was %d/%d.\n\n" , yearday , year , pmonth , pday );
112
111
113
112
// Invalid year
114
113
year = -2587 ;
115
114
yearday = day_of_year (year , month , day );
116
- month_day (year , yearday , pmonth , pday );
115
+ month_day (year , yearday , & pmonth , & pday );
117
116
printf ("%d/%d/%d was day #%d.\n" , month , day , year , yearday );
118
- printf ("day %d of year %d was %d/%d.\n\n" , yearday , year , * pmonth , * pday );
117
+ printf ("day %d of year %d was %d/%d.\n\n" , yearday , year , pmonth , pday );
119
118
return 0 ;
120
119
}
0 commit comments