我有一个函数,我想修改传递给它的cardString[],以便cardString[]包含[charSuit, cardRank, '\0']:

void getCard(int row, int column, char cardString[]){
    PlayingCard myCard = myDeck.cardArray[row][column];
    char charSuit;
    char charRank;

    if (myCard.getSuit() == CLUB)
        charSuit = 'C';
    else if (myCard.getSuit() == SPADE)
        charSuit = 'S';
    else if (myCard.getSuit() == HEART)
        charSuit = 'H';
    else if (myCard.getSuit() == DIAMOND)
        charSuit = 'D';
    if (myCard.getRank() == NINE)
        charRank = '9';
    else if (myCard.getRank() == TEN)
        charRank = 'T';
    else if (myCard.getRank() == JACK)
        charRank = 'J';
    else if (myCard.getRank() == QUEEN)
        charRank = 'Q';
    else if (myCard.getRank() == KING)
        charRank = 'K';
    else if (myCard.getRank() == ACE)
        charRank = 'A';
}

最佳答案

没有单行分配整个数组的方法。您需要编写三个赋值语句:

cardString[0] = charSuit;
cardString[1] = charRank;
cardString[2] = '\0';

08-19 11:28