I want to print month name which is an array element (return from function as a pointer..)
This is my function:
/*I have taken this from book by Dennis Ritchie*/
/* month name : return name of n-th month */
char *month_name(int n){
static char *name[] = {
"illegal month","January","February","March","April","May","June","July",
"August","September","October","November","December"};
return (n < 1 || n > 12) ? name[0] : name[n];
}
Now I am unable to collect this pointer in my main() function. I have tried this way
void main(void)
{
int k = 0, i = 0;
char *s;
printf("Enter month number\n");
scanf("%d",&k);
s = month_name(k);
for(i = 0; *(s+i) != '/0'; i++)
printf("%c",*(s+i));
getch();
}
puts(month_name(k))?'/0'should be'\0'forloop:'/0'should be'\0'