# Thread: Strcpy to and from arrays question from bonehead newb

1. ## Strcpy to and from arrays question from bonehead newb

Im writing a card game. below is the code for the actual deck building witch is based on a previous function which randomizes 52 cards 1- 52.

For the sake of brevity I have only included the specific code.

The problem specifically is the last line which spits out "unterminated macro-like function invocation"

Code:
```#include <stdio.h>#include <strings.h>
#define numcardsuit 13
#define deckcards 52

int main (int argc, const char * argv[])
{
char value[numcardsuit+1][3]={"2","3","4","5","6","7","8","9","10","J","Q","K","A"};
char playdeck[deckcards+1][3];
char shuffledDeck[52];
for (int counter=0; counter < deckcards; counter++) {

if (shuffledDeck[counter] <= numcardsuit) {
strcpy(playdeck[counter],"D");
strcpy(playdeck[counter][counter],value[shuffledDeck[counter]][0];```
I have racked my head for the last 2 nights trying to find a solution before posting but man.. I thought assembly was tuff

by the way, Ill accept any and all advise you can give out. I have a book on C in mail but for right now, its c for dummies and it gives arrays and pointers a single page between them

Micheal

2. The easiest way is to have a single dimension deck of 52 cards.
Shuffling is a breeze...

To get the face divide by 13 ... face = deck[x] / 13
To get the suit us mod 4 ... suit = deck[x] % 4

To display the card use
Code:
```
int deck[52];
char faces[13][3] = {"A","2","3","4","5","6","7","8","9","10","J","Q","K"}
char suits[4][9] = {"Clubs","Hearts","Spades","Diamonds"}

// pick a card... (number between 0 and 51)

printf("The card is %s of %s\n",deck[card / 13], deck[card % 4]);```

No more complex arrays.

Popular pages Recent additions