我从数组中处理卡类型结构。
struct card deck[DECKSIZE]; //The deck is an array of cards structures
我正在使用2D阵列。卡类型结构的数组的数组
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);
}
我用c编程已经很长时间了,所以我认为这是您制作原型的方式?
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);
}
我在编译过程中得到以下2条语句
警告:从不兼容的指针类型传递[dealHands]的参数2 [默认启用] dealHands(deck,allHands,hands,cards);^
注意:预期的'struct card **'但参数的类型为'struct card()[(sizetype)(cards)]'void dealHands(struct card [],struct card [],int,int); ^
当我需要在函数中调用指针和数组时,我总是很困惑。因此,我不确定我的逻辑有何缺陷。我在哪里传递地址而不是值,反之亦然?
喵喔喔
相关分类