472,119 Members | 1,556 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,119 software developers and data experts.

converting month number to month name

3
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 13884
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 Expert Mod 8TB
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
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
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
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

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Christopher Benson-Manica | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.