Wrox Programmer Forums
|
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
  #1 (permalink)  
Old January 4th, 2004, 09:50 PM
ÕÅÃÍ
Guest
 
Posts: n/a
Default 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!:)

Reply With Quote
  #2 (permalink)  
Old January 8th, 2004, 02:11 AM
Authorized User
 
Join Date: Oct 2003
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
  #3 (permalink)  
Old January 30th, 2004, 07:52 AM
Authorized User
 
Join Date: Jan 2004
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ankur_vachhani
Default

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


Reply With Quote
  #4 (permalink)  
Old February 5th, 2004, 10:05 PM
Authorized User
 
Join Date: Feb 2004
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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" };

Reply With Quote
  #5 (permalink)  
Old February 5th, 2004, 10:09 PM
Authorized User
 
Join Date: Feb 2004
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

correcting message above, sorry I ment
char season[ 4 ][]= {expressions }.... or
char* season[ 4 ] = { expressions };

Reply With Quote
  #6 (permalink)  
Old February 24th, 2004, 02:58 PM
Friend of Wrox
 
Join Date: Feb 2004
Posts: 177
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
  #7 (permalink)  
Old February 27th, 2004, 02:27 AM
Registered User
 
Join Date: Jan 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thank you all!

Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
What's wrong ??? FT BOOK: ASP.NET Website Programming Problem-Design-Solution 2 November 3rd, 2005 09:18 AM
Help..What am I doing wrong... Brettvan1 VB.NET 2002/2003 Basics 2 October 18th, 2004 02:36 AM
Where did I go wrong??? ahc2inc VB.NET 2002/2003 Basics 3 September 28th, 2004 08:19 PM
What's wrong?Help! amu BOOK: Beginning ASP.NET 1.0 1 October 28th, 2003 08:21 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.