 |
| C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

January 4th, 2004, 09:50 PM
|
|
|
Right or wrong?
A few days ago,i wrote a program, here is part of it:
char season[][4]={"spring","summer","fall","winter"};
who can tell me it is right or not?
if it is right,how can i output it?
thanks in advance!:)
|

January 8th, 2004, 02:11 AM
|
|
Authorized User
|
|
Join Date: Oct 2003
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
You are on track boy.
You have a two dimensional array.
I think you sh'd use a for loop to loop through the different array elements.
Bye
Programmed
|

January 30th, 2004, 07:52 AM
|
|
Authorized User
|
|
Join Date: Jan 2004
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
YOUR CODE WILL GO LIKE THIS
char season[][]={"spring","summer","fall","winter"};
for(int i = 0 ;i<4;i++)
printf("Season = %s",season[i]);
HTH
|

February 5th, 2004, 10:05 PM
|
|
Authorized User
|
|
Join Date: Feb 2004
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Sorry it's wrong. You are declaring a two-dimensional array. try this
char[ 4 ] [ ] = { { 's', 'p', 'r', 'i', 'n','g'},{'s','u','m','m','e','r'}, {'f','a','l','l'},{'w','i','n','t','e','r'} };
or this
char*[ 4 ] = [ "spring", "summer", "fall", "winter" };
|

February 5th, 2004, 10:09 PM
|
|
Authorized User
|
|
Join Date: Feb 2004
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
correcting message above, sorry I ment
char season[ 4 ][]= {expressions }.... or
char* season[ 4 ] = { expressions };
|

February 24th, 2004, 02:58 PM
|
|
Friend of Wrox
|
|
Join Date: Feb 2004
Posts: 177
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
The code is ok, but the second column size is not big enough to hold the string, so it should be like
char season[][7] = {"spring","summer","fall","winter"};
Otherwise the you can initialize the string like this and you can print the string like season[0], season[1] etc.,
Regards
Pradeep P
Quote:
quote:Originally posted by ÃÃ
ÃÃ
A few days ago,i wrote a program, here is part of it:
char season[][4]={"spring","summer","fall","winter"};
who can tell me it is right or not?
if it is right,how can i output it?
thanks in advance!:)
|
It is not how much we do,
but how much love we put in the doing.
-Mother Theresa
|

February 27th, 2004, 02:27 AM
|
|
Registered User
|
|
Join Date: Jan 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
thank you all!
|
|
 |