Thread: Setting an array equal to another array.

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    24

    Setting an array equal to another array.

    Can I simply take two arrays of the same data type and set one equal to the other in order to copy all of the contents to the second array like this:

    Code:
    typedef struct card
    {
     int face;
     int suit;
     int card_num;
    } Card;
    
    Card p1_hand[5];
    Card p2_hand[5];
    
    //then i have a bunch of code that gives each hand array 5 cards
    then at one point i want to do p1_hand = p2_hand. Will this work or do I need to use a loop to set each index equal to the other?

  2. #2
    Registered User
    Join Date
    Mar 2009
    Posts
    344
    Nope, assignment doesn't work. Either loop or use memcpy().

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Array equal to array
    By xniinja in forum C Programming
    Replies: 15
    Last Post: 01-20-2011, 08:35 PM
  2. Replies: 5
    Last Post: 12-27-2009, 11:04 PM
  3. Setting String equal to char array?
    By Stunner in forum C++ Programming
    Replies: 16
    Last Post: 07-24-2007, 02:41 AM
  4. set string array equal variable
    By WaterNut in forum C++ Programming
    Replies: 3
    Last Post: 06-29-2004, 05:02 PM
  5. array equal to another array
    By dayknight in forum C++ Programming
    Replies: 5
    Last Post: 11-28-2003, 09:45 AM