Another alternative is tables:
Code:
#include <stdio.h>
#include <stdlib.h>
char *getMonth(unsigned imonth)
{
static char *months[] = {
"",
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
};
return (imonth > 12) ? "" : months[imonth];
}
int main(void)
{
char buff[BUFSIZ];
unsigned n;
printf("Enter a number (1-12): ");
fflush(stdout);
if (fgets(buff, sizeof buff, stdin) != NULL) {
n = (unsigned)strtoul(buff, NULL, 0);
puts(getMonth(n));
}
}