i have this function for dealing cards in card game. it is working fine, but i cant figure out how to pass a variable in it. Here is what i mean: This function will deal 5 card. but the user should have the option to change 1 or multiple cards WHILE keeping the other cards. how can i modify this function to do this task?

void deal( int deck[][13], int hand[][2], char *suit[], char *face[] )
{
   int r = 0; /* counter for position in the hand */
   int card, row, column; /* loop counters */

   printf( "The hand is:\n" );

   /* loop to distrubute the cards */
   for ( card = 1; card < 6; card++ )

      for ( row = 0; row <= 3; row++ )

         for ( column = 0; column <= 12; column++ )

            if ( deck[ row ][ column ] == card )
            {
               hand[ r ][ 0 ] = row;
               hand[ r ][ 1 ] = column;
               printf( "%5s of %-8s\n", face[ column ], suit[ row ] );
               ++r;
            } /* end if */

   printf( "\n" );
} /* end function deal */

here are the strings im using:

int deck[ 4 ][ 13 ]; /* represents deck of cards */
int hand1[ 5 ][ 2 ]; /* represents hand */

char *face[ 13 ] = { "Ace", "Deuce", "Three", "Four", "Five",
      "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King" };
char *suit[ 4 ] = { "Hearts", "Diamonds", "Clubs", "Spades" };

thanks for any help!!!

Recommended Answers

All 2 Replies

i have this function for dealing cards in card game. it is working fine, but i cant figure out how to pass a variable in it. Here is what i mean: This function will deal 5 card. but the user should have the option to change 1 or multiple cards WHILE keeping the other cards. how can i modify this function to do this task?

void deal( int deck[][13], int hand[][2], char *suit[], char *face[] )
{
   int r = 0; /* counter for position in the hand */
   int card, row, column; /* loop counters */

   printf( "The hand is:\n" );

   /* loop to distrubute the cards */
   for ( card = 1; card < 6; card++ )

      for ( row = 0; row <= 3; row++ )

         for ( column = 0; column <= 12; column++ )

            if ( deck[ row ][ column ] == card )
            {
               hand[ r ][ 0 ] = row;
               hand[ r ][ 1 ] = column;
               printf( "%5s of %-8s\n", face[ column ], suit[ row ] );
               ++r;
            } /* end if */

   printf( "\n" );
} /* end function deal */

here are the strings im using:

int deck[ 4 ][ 13 ]; /* represents deck of cards */
int hand1[ 5 ][ 2 ]; /* represents hand */

char *face[ 13 ] = { "Ace", "Deuce", "Three", "Four", "Five",
      "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King" };
char *suit[ 4 ] = { "Hearts", "Diamonds", "Clubs", "Spades" };

thanks for any help!!!

Come on people... help me out here.. i really need some help!!!!

You waited a whole 15 minutes? Come on, guy, some of us have lives and don't live on the board!

As to your question, change the deal function to return 1 and only 1 card. Then you can created a dealHands function that will deal as many cards as you need to all people you have playing. Then when you need to draw 2 cards, you call deal twice.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.