These are my two structs:
typedef struct _card {
int suit;
int value;
} card;
typedef struct _deck {
int num_cards;
card *cards;
} deck;
This is my make a card function:
card *make_card(int suit, int value)
{
card *newCard = malloc(sizeof(card));
newCard->suit = suit;
newCard->value = value;
return newCard;
}
Now is where I am a bit stuck. I have to make a deck of cards. I know how to assign each value to the card, but I am stumped on how to allocate it in memory. I know it has to do with an array of cards in the deck struct but i cant figure out how.
deck *make_standard_deck()
{
for (int i = 0; i <= 3; i++)
{
for (int j = 1; j <= 13; j++)
{
deck.cards[i] = make_card(int suit, int value);
}
}
}