I am attempting to fill a deck of cards using c (I am new to c) however I keep getting the error, error: variable-sized object may not be initialized for the line
char **deck[r] = values[v], suits[d], colour[s];
This is the full code. I am attempting to fill a deck of cards and store the deck in the array deck[52] using the colour, suit and value arrays to get each card in the deck. If my logic is wrong then how can I put the suit , face and colour into the deck in order to fill a deck of cards?
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
typedef unsigned char card;
static char *suits[] = { "Hearts", "Diamonds", "Clubs", "Spades" };
static char *values[] = { "Ace", "Two", "Three", "Four", "Five", "Six", \
"Seven", "Eight", "Nine", "Ten", "Jack", \
"Queen", "King" };
static char *colour[] = { "Black", "Red" };
void filldeck(card deck[52]);
int main()
{
filldeck(deck);
return 0;
}
void filldeck(card deck[52])
{
int r;
r = 0;
int v;
int d;
int s;
for ( v = 0; v < 13; v++)
{
for ( d = 0; d < 4; d++)
{
for ( s = 0; s < 2; s++)
{
char **deck[r] = values[v], suits[d], colour[s];
printf("%c", deck[r]);
r++;
}
}
}
return;
}
If I try
deck[r] = values[v], suits[d], colour[s];
warning: assignment makes integer from pointer without a cast
p.s. there are 52 cards in the deck
Please help