#define MAXCARDS 52
char* const CARD[MAXCARDS] = {
"AH","AC","AS","AD","2H","2C","2S","2D",
"3H","3C","3S","3D","4H","4C","4S","4D",
"5H","5C","5S","5D","6H","6C","6S","6D",
"7H","7C","7S","7D","8H","8C","8S","8D",
"9H","9C","9S","9D","TH","TC","TS","TD",
"JH","JC","JS","JD","QH","QC","QS","QD",
"KH","KC","KS","KD" };
The main program could start like this
int main()
{
char* deck[MAXCARDS];
char* hand[2][MAXCARDS];
srand(time(NULL) % RAND_MAX);
for (int i = 0; i < MAXCARDS; i++) {
deck[i] = CARD[i];
}
shufflecards(deck);
...
Suggestion:
void shufflecards(char* deck[MAXCARDS]);
//edit:
Based on Ricks second solution you can write a GenerateDeck Funktion witch combines copy and shuffle.
void GenerateDeck(char* deck[])
{
for (int n=0; n<MAXCARDS; ++n) {
for(;;) { int i = GetRandomInt(0, MAXCARDS - 1);
char* card = CARD[i];
if (!FindCard(deck, card, n)) {
deck[n] = card;
break; }
else {
}
}
}
};
Result:
missfits: 142, 78, 137, 221
5D JS 7D 8D 8S QS 3D TC
3H 4D 2D JH 7S 6C 2C 9D
TH QC 2S KH TS 9C 5S JC
7H TD 8C JD KS 6S QH AS
KD 4S AC 3S 4C 5H KC AD
4H 3C 6D 9H 6H 8H AH 5C
2H QD 9S 7C
However, there are sometimes a lot of failed attempts until the deck is filled.