473,948 Members | 13,796 Online

# converting month number to month name

3 New Member
I am using a function prototype to convert month number to month name.
basically you ask the compiler to enter int from 1 to 12 and then convert it.

printMonth ( number ); is the prototype and using switch this is what i did

case 'm':
printf( "What month? Enter a number between 1 and 12: " );
scanf( "%d%c", &number, &tmp );
printMonth( number );
break;
But i just don't know how to call the function . can someone help.
Oct 15 '07 #1
5 14470
simplebelle
5 New Member
I am using a function prototype to convert month number to month name.
basically you ask the compiler to enter int from 1 to 12 and then convert it.

printMonth ( number ); is the prototype and using switch this is what i did

case 'm':
printf( "What month? Enter a number between 1 and 12: " );
scanf( "%d%c", &number, &tmp );
printMonth( number );
break;
But i just don't know how to call the function . can someone help.
I think the best way you need to use is switch case statement:
here the syntax:
switch(variable _expression){
case constant_value;
{
statement 1;
break;
}
case constant_value;
{
statement 2;
break;
}
statement 3;
break;
}
case constant_value;
{
statement 4;
break;
}

(until 12)
default;
satemen 13
break;
}
Oct 15 '07 #2
weaknessforcats
9,208 Recognized Expert Moderator Expert
case 'm':
printf( "What month? Enter a number between 1 and 12: " );
scanf( "%d%c", &number, &tmp );
printMonth( number ); <<<<<<<this is your call
break;
But i just don't know how to call the function . can someone help.
You just called the function.

What am I missing??
Oct 15 '07 #3
girl23
3 New Member
I think the best way you need to use is switch case statement:
here the syntax:
switch(variable _expression){
case constant_value;
{
statement 1;
break;
}
case constant_value;
{
statement 2;
break;
}
statement 3;
break;
}
case constant_value;
{
statement 4;
break;
}

(until 12)
default;
satemen 13
break;
}
Thank you so much
that helps me a lot
Oct 15 '07 #4
Prasannaa
21 New Member
Hi,

Another simple method. Since month names are not going to change, you can create a static array with month names and just index (after checking for bounds) the array with the number.
Now it becomes a simple array index.

Prasannaa
Oct 18 '07 #5
jwwicks
19 New Member
So something like the following would work...

Expand|Select|Wrap|Line Numbers
1. static char m_months[13][10] = {"", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
2.     string month(m_months[n]);
3.
Where n is the number entered from the user...

John
Oct 19 '07 #6