Please use code tags, as it makes your code much more readable...
I would like to point out that fillDeck() and shuffle() only do the first 52 cards.
To handle dealing cards, I would actually suggest representing your deck of cards as a stack, which is basically an array with an index to it's top.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
struct card {
const char *face;
const char *suit;
};
typedef struct card Card;
// A more sophisticated implementation of Deck might use
// Card * myCards and memory allocation to create a deck of
// any size, instead of just 312
typedef struct {
Card myCards[312];
unsigned int topCard;
} Deck;
void fillDeck( Card * const, const char*[], const char*[] );
void shuffle( Card * const );
void initDeck (Deck * const initMe, const char *face[], const char * suit[]);
void Deal(Deck * const dealMe);
// These are very simple, they just save typing really.
char const * getFace (Deck const * const getMyFace);
char const * getSuit (Deck const * const getMySuit);
// Card * topCard (Deck * getMyTop);
int main()
{
const char *face[] = { "Ace", "Duece", "Three", "Four",
"Five", "Six", "Seven", "Eight",
"Nine", "Ten", "Jack", "Queen", "King"};
const char *suit[] = {"Hearts", "Diamonds", "Clubs", "Spades" };
Deck myDeck;
srand(time(NULL ) );
initDeck (&myDeck, face, suit);
Deal(&myDeck);
return 0;
}
void initDeck (Deck * const initMe, const char * face[], const char * suit[])
{
// Whether you start at 0 and count up, or start at 311 and count
// down is arbitrary.
initMe -> topCard = 0;
fillDeck (initMe -> myCards, face, suit);
shuffle (initMe -> myCards);
return;
}
void fillDeck( Card * const wDeck, const char * wFace[], const char * wSuit[])
{
int i;
for( i = 0; i <= 51; i++) {
wDeck[ i ].face = wFace[ i % 13 ];
wDeck[ i ].suit = wSuit[ i/ 13 ];
}
}
void shuffle( Card * const wDeck )
{
int i, j;
Card temp;
for ( i = 0; i<= 51; i++ ) {
j = rand() % 52;
temp =wDeck[ i ];
wDeck[ i ] = wDeck[ j ];
wDeck[ j ] = temp;
}
}
// Takes the top card off the deck and prints it
void Deal(Deck * const dealMe)
{
printf ("%5s of %-8s", getFace (dealMe), getSuit (dealMe));
dealMe -> topCard++;
return;
}
// These could be implemented as macros
char const * getFace (Deck const * const getMyFace)
{
return getMyFace->myCards[getMyFace->topCard].face;
}
char const * getSuit (Deck const * const getMySuit)
{
return getMySuit->myCards[getMySuit->topCard].suit;
}