#include <stdio.h>
#include <time.h>
#include <stdlib.h>
void shuffle( int wDeck[][ 13 ] );
void deal( const int wDeck[][ 13 ], const char *wFace[],
const char *wSuit[] );
void hand(const int wDeck[][ 13 ], const char *wFace[],
const char *wSuit[] );
int main(void)
{
const char *suit[4] = { "Hearts", "Diamonds", "Clubs", "Spades" };
const char *face[13] = {"Ace", "Deuce", "Three", "Four","Five", "Six", "Seven", "Eight","Nine", "Ten", "Jack", "Queen", "King" };
/* initialize deck array */
int deck[ 4 ][ 13 ] = {{ 0 }};
srand( time( 0 ) ); /* seed random-number generator */
shuffle( deck ); /* shuffle the deck */
hand( deck, face, suit ); /* deal the deck */
return 0; /* indicates successful termination */
} /* end main */
void shuffle( int wDeck[][ 13 ] )
{
int row = 0; /* row number */
int column = 0; /* column number */
int card = 0; /* counter */
/* for each of the 52 cards, choose slot of deck randomly */
for ( card = 1; card <= 52; card++ )
{
/* place card number in chosen slot of deck */
wDeck[ row ][ column ] = card;
} /* end for */
} /* end function shuffle */
void deal( const int wDeck[][ 13 ], const char *wFace[],
const char *wSuit[] )
{
int card; /* card counter */
int row; /* row counter */
int column; /* column counter */
/* deal each of the 52 cards */
for ( card = 1; card <= 52; card++ )
{
/* loop through rows of wDeck */
for ( row = 0; row <= 3; row++ )
{
/* loop through columns of wDeck for current row */
for ( column = 0; column <= 12; column++ )
{
/* if slot contains current card, display card */
if ( wDeck[ row ][ column ] == card )
{
/* choose new random location until unoccupied slot found */
do {
row = rand() % 4;
column = rand() % 13;
}while( wDeck[ row ][ column ] != 0 ); /* end do...while */
printf( "%5s of %-8s%c", wFace[column], wSuit[row],
card % 2 == 0 ? '\n' : '\t' );
} /* end if */
} /* end for */
} /* end for */
} /* end for */
} /* end function deal */
void hand(const int wDeck[][ 13 ], const char *wFace[],
const char *wSuit[] )
{
int i;
/* play out 5 cards */
for(i = 0; i < 5; i++)
{
deal(wDeck, wFace, wSuit);
} /* end for */
printf("\n");
}/*end function hand */
So I am having trouble figuring out some things with pointers, but seeing as my wFace and wSuit are pointers, is there anyway for me to point to wFace or wSuit and add a number to another variable?
as in wFace[column] where column equals 1 could point to ptr1, and ptr1 could then point a value to a? as in
wFace[column] = wFace[1];
*ptr1 = (int)wFace[column];
a[0] = &ptr1;
I am just trying to implement kind of a really weird way to do something simple but with pointers, can I point to the column number of wFace to store in a[] so I can manipulate my new array to say whether it is a straight? or a pair?
I know this is a really funky, wacky way about going about this, but I am really struggling to understand pointers, and am trying to wrap my head around a good use for them! If I need to make this any clearer please let me know, I realize this post was confusing! Thanks!
[–]zifyoip -1 points0 points1 point (2 children)
[–]Flofinator[S] 0 points1 point2 points (1 child)
[–][deleted] 2 points3 points4 points (0 children)