I am writing a program that prints out the value of cards using a structure.
I'm a beginner in data structure and I'm trying to advance my knowledge in this area.
Values of Cards
Face [1 - Ace, 2 - 2, ......, 11 - Jack, 12 - Queen, 13 - King]
Shape [0 - Spades, 1 - Clubs, 2 - Diamonds, 3 - Hearts]
Color [0 - Black, 1 - Red]
I've used the malloc function to allocate memory for 3 cards, which was passed to a pointer name *myCards, with type struct cards.
Code:
struct Cards *myCards;
myCards = (struct Cards *)malloc(3 * sizeof(struct Cards));
I am trying to store 3 cards (Queen Spades, 4 Diamonds, Ace Clubs) in the space of the allocated memory, using the pointer myCards but I'm getting an error when I ran the code.
error(incompatible types when assigning to type 'struct Cards' from type 'int')
My structure
Code:
struct Cards {
int face[13];
int shape[3];
int color[1];
}Cards;
Code for storing the 3 cards
Code:
*(myCards + 0) = 12, 1;
*(myCards + 1) = 4, 2;
*(myCards + 2) = 1, 1;
Enable GingerCannot connect to Ginger Check your internet connection
or reload the browserDisable in this text fieldEditEdit in GingerEdit in Ginger×Enable GingerCannot connect to Ginger Check your internet connection
or reload the browserDisable in this text fieldEditEdit in GingerEdit in Ginger×