i am newbie and trying to explore vC++ by self teach method.I am stuck on arrays.The query is if user inputs a month number the output should be month name.For eg. If 8 is typed in, the output will be august.I have to use 2D array..I suppose.But cant get any further.....
Any help is really appreciated..
thankx

12-07-2001

adrianxw

To declare an array of null terminated strings use...

char Months[12][20];

...the first index is the month you want, the second is the number of characters in each string, (20 may be to many, it would be in English - so set this appropriately).

You can either initialise the array when you create it...

char Months[12][20] = {"January", "February", ... etc.

...or individually...

strcpy(Months[0],"January");

... you should be able to do the rest with this start.

12-07-2001

maes

the first one is the number of the month. you don't have to fill in the number 12 (but it is not wrong if you do)because you initialize it imediatly. there isn't a month name longer then 8 chars so 10 is a save value

Now, since arrays are zero based (array of size 12 would start at 0 and end with 11), you would want to take the number input by the user and subtract 1 for the array position of that month. You should also check to insure the value will fall within the bounds of your array.