|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int str[52];//用于存放随机数
//char str1[3][50] = {0};
const char *data[] = {"黑A","黑2","黑3","黑4","黑5","黑6","黑7","黑8","黑9","黑10",
"红A","红2","红3","红4","红5","红6","红7","红8","红9","红10",
"梅A","梅2","梅3","梅4","梅5","梅6","梅7","梅8","梅9","梅10",
"方A","方2","方3","方4","方5","方6","方7","方8","方9","方10",
"黑J","黑Q","黑K","红J","红Q","红K","梅J","梅Q","梅K","方J","方Q","方K",
"大王","小王"};
//洗牌
int Xipai()
{
int i, j;
time_t t;
srand((unsigned)time(&t));
//生成1-54的伪随机数
for (i = 0;i < 52;i++)
{
str[i] = rand() % 54 + 1;
//printf("%d ",str[i]);
}
printf("\n");
}
//发牌 一一对应
char Fapai()
{
int i, j, k = 0;
char *p[52];
//这里我想将洗牌后的地址对应的指针存入一个指针数组中,使数组中的指针指向洗牌后在data中对应的牌
for(i = 0;i < 52;i++)
{
*p++ = data + str[i];
}
while (*p++ != '\0')
{
printf("%s ", *p);
}
}
我想将洗牌后的地址对应的指针存入一个指针数组中,使数组中的指针指向洗牌后在data中对应的牌,请问该怎么写?
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
const char * data[] = {"黑A","黑2","黑3","黑4","黑5","黑6","黑7","黑8","黑9","黑10","黑J","黑Q","黑K" ,
"红A","红2","红3","红4","红5","红6","红7","红8","红9","红10" ,"红J","红Q","红K" ,
"梅A","梅2","梅3","梅4","梅5","梅6","梅7","梅8","梅9","梅10","梅J","梅Q","梅K" ,
"方A","方2","方3","方4","方5","方6","方7","方8","方9","方10","方J","方Q","方K" ,
"大王","小王"} ;
void Xipai(int d[])
{
int i , j , k ;
time_t t ;
srand((unsigned)time(& t)) ;
for(i = 0 ; i < 54 ; i ++) d[i] = 0 ;
d[0] = rand() % 54 + 1 ;
for(i = 1 ; i < 54 ;) {
k = rand() % 54 + 1 ;
for(j = 0 ; j < i ; j ++) if(d[j] == k) break ;
if(j == i) d[i ++] = k ;
}
}
int main(void)
{
int d[54] = {0} , i ;
Xipai(d) ;
for(i = 0 ; i < 54 ; i ++) {
if(i) printf(",") ;
printf("%s" , data[d[i] - 1]) ;
}
printf("\n") ;
}
|
|