Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void shuffle( int [][ 13 ] );
void deal( const int [][ 13 ], const char *[], const char *[] );
int main()
{
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" };
int deck[ 4 ][ 13 ] = { 0 };
srand( time( 0 ) );
shuffle( deck );
deal( deck, face, suit );
system ("pause");
return 0;
}
void shuffle( int wDeck[][ 13 ] )
{
int row, column, card;
for ( card = 1; card <= 52; card++ ) {
do {
row = rand() % 4;
column = rand() % 13;
} while( wDeck[ row ][ column ] != 0 );
wDeck[ row ][ column ] = card;
}
}
void deal( const int wDeck[][ 13 ], const char *wFace[],
const char *wSuit[] )
{
int card, row, column;
void getPair ( int[][5],int* );
int getSuit ( int );
for ( card = 1; card <= 5; card++ )
for ( row = 0; row <= 3; row++ )
for ( column = 0; column <= 12; column++ )
if ( wDeck[ row ][ column ] == card )
printf( "%5s of %-8s%c",
wFace[ column ], wSuit[ row ],
card % 2 == 0 ? '\n' : '\t' );
printf( "\n" );
getPair (wDeck , wSuit);
}
int getSuit ( int Card )
{
return ( Card-1)/13;
}
void getPair ( int wDeck[][5], int *pSuit )
{
int hand[5]={0};
int cnt_main, cnt_sub;
int s1, s2;
for ( cnt_main = 0; cnt_main <= 4; cnt_main++ )
hand[cnt_main] = wDeck[0][cnt_main];
for ( cnt_main =0; cnt_main <= 4; cnt_main++ )
{
for ( cnt_sub =0; cnt_sub <= 4; cnt_sub++ )
s1 = getSuit( hand[cnt_main] );
s2 = getSuit( hand[cnt_sub] );
if ( s1 == s2 )
printf( "You have a pair of %s", pSuit[s1]);
}
}
well i know ..i am not so good with pointers at the moment it will take some time ..might be after 6 or 7 questions..well this is my first question with pointers... ummm..Salem i am still nt sure about how ur algorithm work ..I went through it but my magic switch isnt on ..Well its giving me warning like
Warning
21 c:\mydocu~1\card_g~1.c
warning: passing arg 1 of `deal' from incompatible pointer type
58 c:\mydocu~1\card_g~1.c
warning: passing arg 1 of `getPair' from incompatible pointer type
58 c:\mydocu~1\card_g~1.c
warning: passing arg 2 of `getPair' from incompatible pointer type
Well i dont know what they mean a explanantion would help alot..and yeah is it my implimantation of pointer that are causing the warning or is it the functions...
Thanks alot