|
1鱼币
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
struct card {
const char *face;
const char *suit;
};
typedef struct card Card;
void f(Card* const wdesk, const char* wface[], const char *wsuit[]);
void s(Card *const wdesk);
void deal(const Card *const wdesk);
int main()
{
Card desk[52];
const char *face[] = { "qwe", "as", "qwer", "rfv", "ijn", "okm", "vfr", "daj",
"yui", "okn", "ygb", "bso" };
const char *suit[] = { "hehe", "rtdfdy", "yyi", "vghggh" };
srand(time(NULL));
f(desk, face, suit);
s(desk);
deal(desk);
return 0;
}
void f(Card * const wdesk, const char *wface[],const char *wsuit[])
{
int i;
for (i = 0; i <= 51; ++i)
{
wdesk[i].face = wface[i % 13];
wdesk[i].suit = wsuit[i / 13];
}
}
void s(Card *const wdesk)
{
int i, j;
Card temp;
for (i = 0; i <= 51; i++)
{
j = rand() % 52;
temp = wdesk[i];
wdesk[i] = wdesk[j];
wdesk[j] = temp;
}
}
void deal(const Card *const wdesk)
{
int i;
for (i = 0; i <= 51; i++)
{
printf("%5s of %-8s", wdesk[i].face, wdesk[i].suit);
if (i % 4 == 0)
printf("\n");
}
}
这个是按书上打得,但是一运行就报错,不知道要改那里(书上也是这样)。然后const 用的多,不知道有没有舍去一些的必要,
|
|