strand函数的疑问
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define NUM_SUITS 4 //定义4种花色。
#define NUM_RANKS 13 // 每种花色有13张牌。
#define TRUE 1
#define FALSE 0
typedef int Bool;
main()
{
Bool in_hand[NUM_SUITS][NUM_RANKS]={0};
int num_cards, rank, suit;
const char rank_code[]={'2','3','4','5','6','7',
'8','9','t','j','q','k','a'}; //牌的数字
const char suit_code[]={'c','d','h','s'}; //牌的颜色
srand((unsigned) time(NULL)); //这行是什么意思呢》小弟有点迷惑。它是什么格式。??????????
printf("enter number 0f cards in hand:"); //输入手里有几张纸牌。
scanf("%d",&num_cards);
printf("your hand: ");
while(num_cards>0)
{
suit=rand()%NUM_SUITS; //
rank=rand()%NUM_RANKS; //
if(!in_hand[suit][rank])
{
in_hand[suit][rank]=TRUE;
num_cards--;
printf(" %c%c", rank_code[rank], suit_code[suit]);
}
}
printf("\n");
return 0;
}
问题如上:谢谢
[解决办法]
#include<time.h>
#include <stdio.h>
#include <conio.h>
#include<stdlib.h>
#define ZHW_LIST
#define ZW_LIST
#include "zwlist.h"
#include <assert.h>
int main(void)
{
const char *p="A23456789 JQK";
int m[4][13];
int pos; //牌代码
int i,j;
stack_zw s=initstack(52);
assert(s!=NULL);
srand(time(NULL)%60); //使用时间初始随机数
while(++s->top<52)
*(m[0]+s->top)=0; //清零
for(s->top=-1; s->top<51;) //
{
pos=rand()%52; //随机数取值0~51
if(*(m[0]+pos)==0) //是否是未洗牌
{
push(s,pos); //进栈
*(m[0]+pos)=1; //设置此牌洗过
}
}
for(j=0; j<13; j++)
for(i=0; i<4; i++)
{
m[i][j]=pop(s);
}
destroysta(s); //销毁栈
printf("\t刘邦\t\t项羽\t\t管仲\t\t张良\n");
for(j=0; j<13; j++)
for(i=0; i<4; i++)
{
if(m[i][j]%13==9)
printf("\t%c%2d\t",m[i][j]/13+3,10);
else printf("\t%c%2c\t",m[i][j]/13+3,p[m[i][j]%13]);
if(i==3) printf("\n");
}
getch();
return 0;
}