Thanks for that info.... but right now I'm getting incorrect hand values (straight, pairs, etc.) after i added the second player.... could you please run this code and steer me in the right direction again? lol thanks.
Code:
/* Classifies a poker hand */
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#define NUM_RANKS 13
#define NUM_SUITS 4
#define NUM_CARDS 5
/* external variables */
int num_in_rank[NUM_RANKS];
int num_in_suit[NUM_SUITS];
bool straight, flush, four, three;
bool straight1, flush1, four1, three1;
int pairs; /* can be 0, 1, or 2 */
int pairs1;
/**********************************************************
* main *
**********************************************************/
int main(void)
{
/**********************************************************
* read_cards: Reads the cards into the external *
* variables num_in_rank and num_in_suit; *
* checks for bad cards and duplicate cards. *
**********************************************************/
bool card_exists[NUM_RANKS][NUM_SUITS];
char ch, rank_ch, suit_ch;
int rank, rank1, suit;
bool bad_card;
int cards_read = 0;
for (rank = 0; rank < NUM_RANKS; rank++) {
num_in_rank[rank] = 0;
for (suit = 0; suit < NUM_SUITS; suit++)
card_exists[rank][suit] = false;
}
char inHand[2][5];
int card;
while (cards_read < NUM_CARDS) {
bad_card = false;
printf("Enter player1 and player2's cards, respectively\n");
printf("(Example: '23456(hit tab here)45678') : \n");
for(card=0;card<5;card++) //player1
scanf("%c", &inHand[0][card]);
for(card=0;card<5;card++) //player2
scanf("\t%c", &inHand[1][card]);
for(card=0;card<5;card++)
{
switch (inHand[0][card]) {
case '0': exit(EXIT_SUCCESS);
case '2': rank = 0; break;
case '3': rank = 1; break;
case '4': rank = 2; break;
case '5': rank = 3; break;
case '6': rank = 4; break;
case '7': rank = 5; break;
case '8': rank = 6; break;
case '9': rank = 7; break;
case 't': case 'T': rank = 8; break;
case 'j': case 'J': rank = 9; break;
case 'q': case 'Q': rank = 10; break;
case 'k': case 'K': rank = 11; break;
case 'a': case 'A': rank = 12; break;
default: bad_card = true;
}
switch (inHand[1][card]) {
case '0': exit(EXIT_SUCCESS);
case '2': rank1 = 0; break;
case '3': rank1 = 1; break;
case '4': rank1 = 2; break;
case '5': rank1 = 3; break;
case '6': rank1 = 4; break;
case '7': rank1 = 5; break;
case '8': rank1 = 6; break;
case '9': rank1 = 7; break;
case 't': case 'T': rank1 = 8; break;
case 'j': case 'J': rank1 = 9; break;
case 'q': case 'Q': rank1 = 10; break;
case 'k': case 'K': rank1 = 11; break;
case 'a': case 'A': rank1 = 12; break;
default: bad_card = true;
}
if (bad_card)
printf("Bad card; ignored.\n");
else {
num_in_rank[rank]++;
num_in_rank[rank1]++;
num_in_suit[suit]++;
card_exists[rank][suit] = true;
card_exists[rank1][suit] = true;
cards_read++;
}
}
}
//**********************************************************
//******************************************************************************
//Printout Cards
//******************************************************************************
for(card=0; card<5; card++)
{
printf("%c", inHand[0][card]);
}
printf("\t");
for(card=0; card<5; card++)
{
printf("%c", inHand[1][card]);
}
//**********************************************************
//**********************************************************
// analyze_hand: player 1 *
// **********************************************************/
{
int num_consec = 0;
bool straights = false;
flush = false;
four = false;
three = false;
pairs = 0;
/* check for straight */
rank = 0;
while (num_in_rank[rank] == 0) rank++;
for (; rank < NUM_RANKS && num_in_rank[rank] > 0; rank++)
num_consec++;
if (num_consec == NUM_CARDS) {
straight = true;
}
/* check for 4-of-a-kind, 3-of-a-kind, and pairs */
for (rank = 0; rank < NUM_RANKS; rank++) {
if (num_in_rank[rank] == 4) four = true;
if (num_in_rank[rank] == 3) three = true;
if (num_in_rank[rank] == 2) pairs++;
}
}
//**********************************************************
// analyze_hand: player 2 *
// **********************************************************/
{
int num_consec = 0;
bool straights1 = false;
bool flush1 = false;
bool four1 = false;
bool three1 = false;
int pairs1 = 0;
/* check for straight */
rank1 = 0;
while (num_in_rank[rank1] == 0) rank1++;
for (; rank1 < NUM_RANKS && num_in_rank[rank1] > 0; rank1++)
num_consec++;
if (num_consec == NUM_CARDS) {
straight1 = true;
}
/* check for 4-of-a-kind, 3-of-a-kind, and pairs */
for (rank1 = 0; rank1 < NUM_RANKS; rank1++) {
if (num_in_rank[rank1] == 4) four1 = true;
if (num_in_rank[rank1] == 3) three1 = true;
if (num_in_rank[rank1] == 2) pairs1++;
}
}
/**********************************************************
* print_result 1 *
**********************************************************/
if (four) printf("\tFour of a kind");
else if (three &&
pairs == 1) printf("\tFull house");
else if (flush) printf("Flush");
else if (straight) printf("\tStraight");
else if (three) printf("\tThree of a kind");
else if (pairs == 2) printf("\tTwo pairs");
else if (pairs == 1) printf("\tPair");
else printf("\tHigh card");
/**********************************************************
* print_result 2 *
**********************************************************/
if (four1) printf("\tFour of a kind");
else if (three1 &&
pairs1 == 1) printf("\tFull house");
else if (flush1) printf("Flush");
else if (straight1) printf("\tStraight");
else if (three1) printf("\tThree of a kind");
else if (pairs1 == 2) printf("\tTwo pairs");
else if (pairs1 == 1) printf("\tPair");
else printf("\tHigh card");
getch();
printf("\n\n");
}