Declaration with structures

I am trying to declare a struct called Hand. I need to declare an array of type Hand that can hold 52 cards. Am I doing this correctly? To be clear, it is one hand that can contain up to 52 cards. Obviously, one hand will have way less than 52 cards, but nonetheless can hold up to that number.

1
2
3
4
5
6
7

#define cards 52


struct Hand {
       int numCards;
} TheHand [cards];
You are declaring an array of hands that is 52 members long. You don't need 52 hands, just one hand with 52 cards.
1
2
3
typedef struct Hand{
int numCards[52];
}TheHand;


Also, don't use #define, use const int instead:
 
const int cards = 52;
Last edited on
Thank you.
Topic archived. No new replies allowed.