Thread: Initializing a typdef array

  1. #1
    Registered User
    Join Date
    Oct 2011

    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:

    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;
            if(comp_hand[i] == NULL)
                deal(wDeck, wFace, wSuit, top_of_deck, comp_hand, (i+1));
    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:

    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
    Long Beach, CA
    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:
    #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, 10: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