i have been trying to figure out how to do this for the last few days. my book doesnt really have any examples i can follow. i made a 52 card deck, shuffle, and then deal 5 cards. now it needs to say if there is a pair, 2 pair, 3 of a kind, straight, or flush. i thought i should use a pointer to somehow refer to the columns with the cards' face values in them, then compare them for the pairings and straight, and a pointer to refer to the rows with the cards' suits in them for the flush. is this even possible? i was also thinking i could store the values of the column or row into chars to be later compared, but i dont know of a way to do this without the chars being overwritten each time the funcion loops through. if anyone can try to explain to me what needs to happen, suggest a way to go about doing it, or point me to a good example (i already went through many searches for card, poker and found one that dealt with my problem but i didnt understand it), but hopefully just explain to me how the actions i need to have the program perform work. thanks in advance, here is what i have so far, nothing with comparing in it.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void shuffle( int wdeck[][13]);
void deal( const int wdeck[][13], const char *wface[],
const char *wsuit[]);
void pair( int a[]);
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);
pair(face);
return 0;
}
void shuffle(int wdeck[][13])
{
int row;
int column;
int 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;
int row;
int column;
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\n\n", wface[column], wsuit[row],
card % 1 == 0 );
}
}
}
}
}