Programming practice:Analog CARDS shuffle
/*****************************************************************************************Programming practice:Analog CARDS shuffle
******************************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
struct cards{
char *suit[100];
char *face[100];
};
typedef struct cards CARDS;
void xipai(CARDS *wCards);
void fapai(CARDS *wCards);
void FillCard(CARDS wCard[],char *wFace[],char *wSuit[]);
int main(void)
{
char *suit[] = {"heitao","hongxing","meihua","fangpain"};
char *face[] = {"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
CARDS card[52];
srand(time(NULL));
FillCard(card,face,suit);
xipai(card);
fapai(card);
printf("\n");
return 0;
}
void FillCard(CARDS wCard[],char *wFace[],char *wSuit[])
{
int i;
for(i = 0;i < 52;i++)
{
strcpy(wCard[i].face,wFace[i % 13]);
strcpy(wCard[i].suit,wSuit[i / 13]);
}
}
void xipai(CARDS *wCards)
{
int i,j;
CARDS temp;
for(i = 0;i < 52;i++)
{
j = rand() % 52;
temp = wCards[i];
wCards[i] = wCards[j];
wCards[j] = temp;
}
}
void fapai(CARDS *wCards)
{
int i;
for(i = 0;i < 52;i++)
{
printf("%10s%10s",wCards[i].suit,wCards[i].face);
if(i == 4)
printf("\n");
}
}