/* SHUFFLE.C - rearranges a given set of specific objects - in this case a deck of playing cards - into random order. This illustrates the proper use of the subroutine shuffle(). */ #include #include #include #define N 52 // number of objects in the set - 52 for a deck of cards #define NMAX 100 /* maximum number that shuffle() can rearrange: must be greater than or equal to N */ typedef struct { int word1; int word2; } dword; // structure needed by shuffle() char *suit[4] = {"spades", "hearts", "clubs", "diamonds"}; char *value[13] = {"ace", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "jack", "queen", "king"}; void shuffle(int, int *, unsigned int); // function prototypes int compare(dword *, dword *); main() { int i; int a[N]; // one-dimensional array to be shuffled unsigned int see; // arbitrary integer to seed rand() long tval; seed = (unsigned int) (time(&tval) % 65536); // random seed based on time shuffle(N, a, seed); for(i=0; iword1 - elem2->word1); }