473,324 Members | 1,646 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 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 14343
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

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

Similar topics

2
by: Christopher Benson-Manica | last post by:
What would be the best way to convert a month number to its corresponding string? I.e, 3 -> 'March'. Is there a builtin function or must I use a lookup table or something? -- Christopher...
1
by: Wayfarer | last post by:
I've built a report using a aggregate query that is grouped by Month + Year, Program and Name. When I feed the date ranges as query parameters, it will very properly print out a report that shows...
7
by: hasanainf | last post by:
Hi all, I have two querys QueryPurchased ProductID Location TotPcs Prod1 Loc1 100 Prod2 Loc1 50 Prod3 Loc1 150 Prod3 Loc3 150
11
by: Ken Varn | last post by:
I want to be able to determine my current line, file, and function in my C# application. I know that C++ has the __LINE__, __FUNCTION__, and __FILE___ macros for getting this, but I cannot find a...
10
by: Bill | last post by:
Hello -- I'm parsing the output of the finger command, and was wondering something...If I'm given a month abbrievation (such as "Jan"), what's the best way to figure out the month number? I see...
3
by: Aussie Rules | last post by:
Hi, How do I extract just the month part of a date. Say for example I wanted to get the value of 6 (as in sixth month) from todays date. Regards
2
by: CindySue | last post by:
Hello--I've got a query that uses DatePart("m",) to select records for a particular month, and then a report based on that query. I'd like to be able to create a field in the report that says what...
12
by: Be Borth | last post by:
I saw previous solutions to convert a month number (1) to a month name (January). I have a database with 200+ dates. In a query, I use the "Part" function DatePart("m",), to extract the month...
3
antonopn
by: antonopn | last post by:
Hello to all! I'm trying to make a very difficult report. I want to present sales of some products within an year but month-to-month. lets say that the table would be like this... ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.