Now that we have all of our new structures and modifications to the functions that operate on them, we are now ready to put everything into play, so to speak. Modify the main() function routine in carddeck_3.c, as follows:
int main( void ) {
Deckdeck;
Deck* pDeck = &deck;
InitializeDeck( pDeck );
PrintDeck(pDeck );
ShuffleDeck( pDeck );
PrintDeck( pDeck );
Hand h1 , h2 , h3 , h4;
Hand* hands[] = { &h1 , &h2 , &h3 , &h4 };
for( int i = 0 ; i < kNumHands ; i++ ) {
InitializeHand( hands[i] );
}
for( int i = 0 ; i < kCardsInHand ; i++ ){
for( int j = 0 ; j < kNumHands ; j++ )
{
AddCardToHand( hands[j] , DealCardFromDeck( pDeck ) );
}
}
PrintAllHands( hands );
PrintDeck( pDeck );
}
Does it come as a surprise how few lines of code in main() are needed to express all of the work that the program is doing? This was achieved through the use of our manipulation functions. Let's walk through it:
- First, we declare a deck...