gpt4 book ai didi

c - 打印的元素显示出意想不到的值

转载 作者:行者123 更新时间:2023-11-30 20:51:09 24 4
gpt4 key购买 nike

这是我的代码。它调用了一些函数,但没有任何与问题相关的函数。

int main()
{



srand((unsigned int)time(NULL)); //initializing srand

struct card *deckAr = createDeck(); //creating the struct card deck array

for (int i = 0; i < 100000; i++)
{
shuffleDeck(deckAr);
}



struct card *player1hand = (struct card*)malloc(sizeof(player1hand));
struct card *player2hand = (struct card*)malloc(sizeof(player2hand));
struct card *househand = (struct card*)malloc(sizeof(househand));

player1hand = (struct card*)realloc(player1hand, sizeof(player1hand) * 2);
player1hand[0] = deckAr[0];
player1hand[1] = deckAr[1];

printf("Card 1 %s of %s\n\n", valueName(player1hand[0].suit), suitName(player1hand[0].suit));
printf("Card 2 %s of %s\n\n", valueName(player1hand[1].suit), suitName(player1hand[1].suit));
printf("%s of %s\n", valueName(deckAr[0].value), suitName(deckAr[0].suit));


return 0;
}

输出:

Card 1 Three of Hearts

Card 2 Three of Hearts

Ten of Hearts

既然没有任何东西在操纵deckAr,那么deckAr[0]不应该与player1hand[0]相同吗?

最佳答案

你打印这个:

valueName(player1hand[0].suit)

但我认为你的意思是:

valueName(player1hand[0].value)

关于c - 打印的元素显示出意想不到的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34611531/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com