Hi Dan...
I've always found the easiest way to model a deck of cards is as a single numerical array.
Essentially you assign the array values from 0 to 51 then shuffle it.
The suit of any given card (array value) is the number / 13, which in a deck numbered 0 to 51, returns 0 to 3.
The face value of the card is the number % 13, which returns 0 to 12 to represent the card's face value.
To print these out, you use constant arrays, one for the name of the face value, one for the names of the suits.
Here is a little demonstration piece to show you the concepts... DO NOT simply copy this code. Study it, learn how it works, then write your own version of it... You don't learn anything by taking the easy way out, plus teachers do check here so you'd probably just get nailed for cheating!
Code:
// deck of cards demonstration
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <ctype.h>
#define CARDS 52
const char *face[] = {"Ace","Two","Three","Four","Five","Six","Seven",
"Eight","Nine","Ten","Jack","Queen","King" };
const char *suit[] = {"Spades","Hearts","Clubs","Diamonds"};
// function to shuffle the deck
int Shuffle(int *deck)
{
int i, temp, card;
printf("\nShuffling...\n\n");
for (i = CARDS - 1; i > 0; i--)
{
card = rand() % i;
temp = deck[i];
deck[i] = deck[card];
deck[card] = temp;
}
return 0;
}
// program entry point
int main (void)
{
int deck[CARDS]; // deck
int card = 53; // card
int fac, sut; // face and suit
int i; // counter
char ch = 0; // keyboard
printf("The card dealer....\n\n);
srand(time(NULL));
//initialize the deck
for (i = 0; i < CARDS; i++)
deck[i] = i;
// deal cards
do
{
if ( card >= CARDS )
card = Shuffle(deck);
// face and suit
fac = deck[card] % 13;
sut = deck[card] / 13;
// display the card
printf("%2d > %s of %s\t\t",card,face[fac],suit[sut]);
card++;
printf("(Enter to deal, Q to quit)\n");
ch = getchar();
}
while( toupper(ch) != 'Q');
return 0;
}