#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define NUM_PLAYERS 2
#define NUM_CARDS 5

typedef struct {
    int value;
    char suit;
} Card;

typedef struct {
    Card cards[NUM_CARDS];
} Hand;

// Function to initialize a deck of cards
void initializeDeck(Card *deck) {
    int cardIndex = 0;
    for (int suit = 0; suit < 4; ++suit) {
        for (int rank = 2; rank <= 14; ++rank) {
            deck[cardIndex].value = rank;
            switch (suit) {
                case 0:
                    deck[cardIndex].suit = 'H';  // Hearts
                    break;
                case 1:
                    deck[cardIndex].suit = 'D';  // Diamonds
                    break;
                case 2:
                    deck[cardIndex].suit = 'C';  // Clubs
                    break;
                case 3:
                    deck[cardIndex].suit = 'S';  // Spades
                    break;
            }
            cardIndex++;
        }
    }
}

// Function to shuffle a deck of cards
void shuffleDeck(Card *deck) {
    for (int i = 0; i < 52; ++i) {
        int randomIndex = rand() % 52;
        Card temp = deck[i];
        deck[i] = deck[randomIndex];
        deck[randomIndex] = temp;
    }
}

// Function to print a card
void printCard(Card card) {
    printf("%d%c ", card.value, card.suit);
}

// Function to deal cards to players
void dealCards(Card *deck, Hand *playerHands) {
    for (int i = 0; i < NUM_PLAYERS; ++i) {
        for (int j = 0; j < NUM_CARDS; ++j) {
            playerHands[i].cards[j] = deck[NUM_CARDS * i + j];
        }
    }
}

int main() {
    srand(time(NULL));  // Seed for random number generation

    Card deck[52];
    Hand playerHands[NUM_PLAYERS];

    initializeDeck(deck);
    shuffleDeck(deck);

    dealCards(deck, playerHands);

    printf("Welcome to Texas Hold'em!\n");

    for (int i = 0; i < NUM_PLAYERS; ++i) {
        printf("\nPlayer %d's hand:\n", i + 1);
        for (int j = 0; j < NUM_CARDS; ++j) {
            printCard(playerHands[i].cards[j]);
        }
        printf("\n");
    }

    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: