我从数组中处理卡类型结构。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); ^当我需要在函数中调用指针和数组时,我总是很困惑。因此,我不确定我的逻辑有何缺陷。我在哪里传递地址而不是值,反之亦然?
3 回答
喵喔喔
TA贡献1735条经验 获得超5个赞
如果您非常仔细地阅读了我的答案(我想我在答案中写道),您会发现您错了。如果缺少特定信息,请随时发表评论(适当时)。如果您不了解其中的基本知识(无冒犯),请了解堆栈溢出不是教程站点。在这种情况下,您应该读一本上帝(比K&R还新)的C书。
- 3 回答
- 0 关注
- 546 浏览
添加回答
举报
0/150
提交
取消