Thread: Strcpy to and from arrays question from bonehead newb

  1. #1
    Registered User
    Join Date
    Oct 2011

    Red face 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"

    #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) {
    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

    Thanks for your help in advance

  2. #2
    Join Date
    Aug 2010
    Ontario Canada
    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
    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.
    Last edited by CommonTater; 10-16-2011 at 02:44 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newb question: Modifying Arrays
    By Almina in forum C++ Programming
    Replies: 1
    Last Post: 07-07-2008, 11:17 PM
  2. Help with strcpy and arrays
    By doyle96 in forum C++ Programming
    Replies: 3
    Last Post: 05-19-2007, 03:35 PM
  3. Okay, so does this make me a true bonehead.
    By cdalten in forum C Programming
    Replies: 2
    Last Post: 04-27-2006, 09:42 PM
  4. newb question on ARRAYS
    By viciousv322 in forum C++ Programming
    Replies: 18
    Last Post: 11-16-2005, 07:34 PM
  5. strcpy error with arrays
    By trang in forum C Programming
    Replies: 4
    Last Post: 01-10-2004, 10:13 PM