I am trying to make a game of lives and this is the start of my code. The rest of my project is looking fine but I can't run it until I can properly assign memory to my struct "stack".
typedef enum {
CLUBS = 1,
HEARTS,
SPADES,
DIAMONDS
} cardsuit;
typedef enum {
ACE_OF = 1,
TWO_OF,
THREE_OF,
FOUR_OF,
FIVE_OF,
SIX_OF,
SEVEN_OF,
EIGHT_OF,
NINE_OF,
TEN_OF,
JACK_OF,
QUEEN_OF,
KING_OF
} cardvalue;
typedef struct {
enum cardsuit *suit;
enum cardvalue *value;
} card;
typedef struct {
int *size;
int *index;
int *indexOfPlay;
card deck[];
} stack;
int main() {
stack player1;
stack player2;
stack playStack;
stack drawStack;
int num = 1;
int ds = 1;
printf("Please enter the number of decks you wish to use:");
scanf("%d", &num);
ds = DECK*num;
printf("\nYou have chosen to have %d decks, ie: %d cards.\n", num, ds);
player1 = (stack *) malloc(sizeof (stack)*num);
player2 = (stack *) malloc(sizeof (stack)*num);
player1.deck = malloc( sizeof(player1)*num);
player2.deck = (card *) malloc(sizeof(card)*num);
playStack = (stack *) malloc(sizeof (stack)*num);
drawStack = (stack *) malloc(sizeof (stack)*num);
}
When I run my code like this I get an incompatible types in assignment for each of my malloc
calls. My question is what is the correct way to assign memory to my struct stack
?