We wouldn't normally write separate functions for each of the hand categories since they are so interrelated. It's best to gather information about the number of pairs, trips, quads, and whether there is a flush and/or straight, then use that data to determine the category.
This is untested (partly pseudocode) but shows the idea.
Code:
int value(Card card) {
return value of card from 2 to 14 (ace)
}
int suit(Card card) {
return suit of card from 0 to 3
}
int analyze_hand(Card *hand) {
int v[NUM_VALUES] = { 0 }, s[NUM_SUITS] = { 0 };
int pairs = 0, trips = 0, quads = 0, flush = 0, straight = 0;
int num_in_a_row = 0;
for (int i = 0; i < NUM_CARDS_IN_HAND; i++) {
++v[value(hand[i]) - 2];
if (++s[suit(hand[i])] == NUM_CARDS_IN_HAND)
flush = 1;
}
for (int i = 0; i < NUM_VALUES; i++) {
if (v[i] > 0) {
if (++num_in_a_row == NUM_CARDS_IN_HAND)
straight = 1;
if (v[i] == 2) pairs++;
else if (v[i] == 3) trips++;
else if (v[i] == 4) quads++;
}
else
num_in_a_row = 0;
}
if (flush && straight) printf("straight flush\n");
else if (quads == 1) printf("four of a kind\n");
else if (trips == 1 && pairs == 1) printf("full house\n");
else if (flush) printf("flush\n");
else if (straight) printf("straight\n");
else if (trips == 1) printf("three of a kind\n");
else if (pairs == 2) printf("two pair\n");
else if (pairs == 1) printf("one pair\n");
else printf("no pair\n");
}
This assumes that ace-low straights (and straight flushes) aren't allowed (i.e., aces always have a value of 14 and never 1).
And it doesn't distinguish between straight flush and royal flush (which is just the highest straight flush). You could do that by first checking if it's a straight flush and then checking that it contains an ace.