I get the following warning when I try to compile the code:
program141.c:13:5: warning: format ‘%i’ expects argument of type ‘int *’, but argument 2 has type ‘enum month *’ [-Wformat]
// Program to print the number of days in a month
#include <stdio.h>
int main (void)
{
enum month { january = 1, february, march, april, may, june,
july, august, september, october, november, december };
enum month aMonth;
int days;
printf ("Enter month number: ");
scanf ("%i", &aMonth);
switch (aMonth) {
case january:
case march:
case may:
case july:
case august:
case october:
case december:
days = 31;
break;
case april:
case june:
case september:
case november:
days = 30;
break;
case february:
days = 28;
break;
default:
printf ("bad month number\n");
days = 0;
break;
}
if ( days != 0 )
printf ("Number of days is %i\n", days);
if ( aMonth == february )
printf ("...or 29 if it's a leap year\n");
return 0;
}
This code is from a book I'm reading.
How do I fix this warning?