struct card {
const char *face;
const char *suit;
};
typedef struct card Card;
void fillDeck( Card * const, const char*[], const char*[] );
void shuffle( Card * const );
void Deal( const Card * const );
int main()
{
Card deck[312];
const char *face[] = { "Ace", "Duece", "Three", "Four",
"Five", "Six", "Seven", "Eight",
"Nine", "Ten", "Jack", "Queen", "King"};
const char *suit[] = {"Hearts", "Diamonds", "Clubs", "Spades" };
srand(time(NULL ) );
fillDeck( deck, face, suit );
shuffle( deck);
Deal( deck );
return 0;
}
void fillDeck( Card * const wDeck, const char * wFace[], const char * wSuit[])
{
int i;
for( i = 0; i <= 51; i++) {
wDeck[ i ].face = wFace[ i % 13 ];
wDeck[ i ].suit = wSuit[ i/ 13 ];
}
}
void shuffle( Card * const wDeck )
{
int i, j;
Card temp;
for ( i = 0; i<= 51; i++ ) {
j = rand() % 52;
temp =wDeck[ i ];
wDeck[ i ] = wDeck[ j ];
wDeck[ j ] = temp;
}
}
void Deal( const Card * const wDeck)
{
This is where I am having a problem. I want to use this shufflling program code, but how do I get it to print out just one card everytime I call this function. I tried
int i;
i = 0;
while ( i++ && i<= 300)
printf("%5s of %-8%s", wDeck[ i ].face, wDeck[ i ].suit, '\n' );
The entire code compiled but wouldn't print out one card liked I wanted it to. Help!!
}![]()



LinkBack URL
About LinkBacks



