problem initializing an array

This is a discussion on problem initializing an array within the C++ Programming forums, part of the General Programming Boards category; Ok I have the function Code: void card::SetCards() { name[52][4] = { "H:A", "H:2", "H:3", "H:4", "H:5", "H:6", "H:7", "H:8", ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    61

    problem initializing an array

    Ok I have the function
    Code:
    void card::SetCards()
    {
        name[52][4] = {
        "H:A", "H:2", "H:3", "H:4", "H:5", "H:6", "H:7", "H:8", "H:9", "H:10", "H:J", "H:Q", "H:K",
        "D:A", "D:2", "D:3", "D:4", "D:5", "D:6", "D:7", "D:8", "D:9", "D:10", "D:J", "D:Q", "D:K",
        "C:A", "C:2", "C:3", "C:4", "C:5", "C:6", "C:7", "C:8", "C:9", "C:10", "C:J", "C:Q", "C:K",
        "S:A", "S:2", "S:3", "S:4", "S:5", "S:6", "S:7", "S:8", "S:9", "S:10", "S:J", "S:Q", "S:K"
        };
    }
    and name[54][4] is a char.
    When I try to compile my compiler (dev-c++) gives me the error

    parse error before `{'

    at the line


    name[52][4] = {

    can anyone tell me what's wrong?
    thanks!

  2. #2
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    try this...

    Code:
    char name[54][4] = {
    you need to give it a type...
    hasafraggin shizigishin oppashigger...

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    61
    name[52][4] is already delcared inside of my class.
    Code:
    class card
    {
        char name[52][5];
        int CardNum[52];
        int CurrentCard;
        char buf[10];
    
        void SetCardsInOrder();
        void SwitchCards(int* card1, int* card2);
        void SetCards();
    
      public:
    
        card();
        ~card();
        void Shuffle();
        char* DrawCard();
    };

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    412
    You can't set an array like this. You can only set an array to a series of values ONCE, when you originally declare it.

    So, this will work:

    int arr[2] = {0,1};

    but this won't:

    int arr[2];

    arr = {0,1};

  5. #5
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    1 possible solution is to declare a local array in the function filled as you want and then use memmove() or memcpy() to copy it to your private array.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  6. #6
    Registered User
    Join Date
    Aug 2001
    Posts
    61
    Thanks for your help everyone!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 02-15-2005, 10:20 PM
  2. Problem Putting INTs Into a CHAR Array
    By cram in forum C++ Programming
    Replies: 13
    Last Post: 10-13-2004, 07:53 AM
  3. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM
  4. From stream/file to a string array problem
    By dradsws in forum C Programming
    Replies: 2
    Last Post: 10-01-2001, 06:24 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21