/ 猿问

# 传递2D结构数组

2019-11-20 10:45:24

struct card deck[DECKSIZE];  //The deck is an array of cards structures

struct card allHands[hands][cards];

void dealHands(struct card *deck, struct card **handArray, int hands, int cards){

int players;

int cardCount;

int passCard = 0;

struct card * thisDeck;

thisDeck = deck;

for(players = 0; players < hands; players++){

for(cardCount = 0; cardCount < cards; cardCount++){

handArray[players][cardCount] = thisDeck[passCard];

passCard++;

}

}

deck = (deck + passCard);

}

void dealHands(struct card[], struct card*[], int, int);

int main(int argc, char *argv[])

{

/* Declare and initialize variables  */

int hands = atoi(argv[HANDSINPUT]);  //How many players

int cards = atoi(argv[CARDSINPUT]);  //How many cards per hand

struct card deck[DECKSIZE];  //The deck is an array of cards structures

struct card allHands[hands][cards];

//Builds the deck

//Shuffles deck with a RNG and swapping every card

int players;

int cardCount;

int passCard = 0;

dealHands(deck, allHands, hands, cards);

}

## 3 回答

int a[1][2];    // 1 = outer dimension, 2 = inner

void f(int a[1][2]);

int (*a)[2]   // pointer to array of inner dimension

void f(int (*a)[2]);

int t, i;    // index variable for ouTer, Inner

a[t][i];

int a[1];

int *a;

（我只使用了常量1并2为尺寸编号；当然，您可以使用所需的尺寸。）

f(int inner, a[][inner]);

f(int outer, int inner, a[outer][inner]);

void set_up_array(int **array, int row_size, int column_size){

for(int i = 0; i < row_size; i++){

for(int j = 0; j < column_size; j++){

*((int*)array + i*row_size + j) = i + j + k;

}

}

}

array[y][x]

• 3 回答
• 0 关注
• 50 浏览

0/150