Initializing a typdef array

This is a discussion on Initializing a typdef array within the C Programming forums, part of the General Programming Boards category; What value does the compiler give an array created with an enumerated typedef? For example, I want to do this ...

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    24

    Initializing a typdef array

    What value does the compiler give an array created with an enumerated typedef? For example, I want to do this check:

    Code:
    void switch_comps_card (Card comp_hand[5], const int wDeck[][13], const char *wFace[], const char *wSuit[], int *top_of_deck)
    {
        int i = 0;
        do
        {
            if(comp_hand[i] == NULL)
            {
                deal(wDeck, wFace, wSuit, top_of_deck, comp_hand, (i+1));
            }
            i++;
        }while(i<5);
    }
    However, it says, theres an invalid operand to binary == (have 'Card' and 'Void *')

    So if I can't compare the array to NULL what can I check for? Basically, comp_hand is an array that stores 5 cards for poker. I want to check if there is no card in each index of the array. Usually with an integer array I can use:

    Code:
    int myArray[10] = {0}
    and then check for 0's to see if the indexed array has been given a value of not 0. But how can I do this if the array is of type Card which is a typdef data type?

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,287
    The error implies that Card is not a typedef'ed pointer (generally typedef'ing pointers is not recommended), so comparing it to NULL (a special pointer constant) doesn't make sense. The types are not compatible, hence your error. We would have to see the definition of Card to know what values are valid and exactly what to check for.


    As an aside, it's more common to use a for loop for array processing. I recommend:
    Code:
    #define CARDS_IN_HAND    5  // yay for named constants!
    ...
    for (i = 0; i < CARDS_IN_HAND; i++)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem initializing a double array for large array
    By gkkmath in forum C Programming
    Replies: 4
    Last Post: 08-25-2010, 08:26 PM
  2. typdef, struct, and header files
    By maxzoran in forum C Programming
    Replies: 11
    Last Post: 08-11-2010, 06:41 PM
  3. Typdef struct and function pointers
    By tempster09 in forum C Programming
    Replies: 1
    Last Post: 12-06-2009, 09:16 AM
  4. Initializing a 4-D array
    By gkoenig in forum C Programming
    Replies: 28
    Last Post: 08-13-2008, 10:55 PM
  5. struct -- typdef/ self referential
    By cdave in forum C Programming
    Replies: 7
    Last Post: 04-25-2005, 08:18 PM

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