我有一个功能,我想修改传递给它的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';
}
答案 0 :(得分:2)
没有单行方式来分配整个数组;你需要写三个赋值语句:
cardString[0] = charSuit;
cardString[1] = charRank;
cardString[2] = '\0';