Let's create a function to print the contents of the hand. This function will use a function that we will create to print the structures it contains. In this way, the minimum amount of code is used since printing an individual card exists in only one function. The following function takes our struct Hand as an input parameter, determines which card we are dealing with, and calls printCard() with that card as a parameter, as follows:
void printHand( struct Hand h ) {
for( int i = 1; i < h.cardsDealt+1 ; i++ ) { // 1..5
struct Card c;
switch( i ){
case 1: c = h.c1; break;
case 2: c = h.c2; break;
case 3: c = h.c3; break;
case 4: c = h.c4; break;
case 5: c = h.c5; break;
default:return; break;
}
printCard( c );
}
}
In the preceding printHand() function, we iterate over the number of cards in our hand. At each iteration, we figure out which card we are looking at and copy it to a temporary variable so...