标题:用结构体洗牌
取消只看楼主
wandison
Rank: 1
等 级:新手上路
帖 子:50
专家分:4
注 册:2006-11-7
 问题点数:0 回复次数:0 
用结构体洗牌

我写个用结构体洗牌的,有两个报错不会改
#include<stdio.h>
#include<stdlib.h>
#include<time.h>

struct card{
char *face;
char *suit;
}

typedef struct card Card;

void fill(Card*,char*[],char*[]);
void shuffle(Card*);
void deal(Card*);

main()
{
Card deck[52];
char*face[]={"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
char*suit[]={"1","2","3","4"};
srand(time(NULL));

fill(deck,face,suit);
shuffle(deck);
deal(deck);
return 0;
}

void fill(Card*wdeck,char*wface[],char*wsuit[])
{
int i;

for(i=0;i<52;i++){
wdeck[i].face=wface[i%13];
wdeck[i].suit=wsuit[i/13];
}
}

void shuffle(Card*wdeck)
{
int i,j;
Card temp;

for(i=0;i<52;i++){
j=rand()%52;
temp=wdeck[j];
wdeck[j]=temp;
}
}

void deal(Card*wdeck)
{
int i;

for(i=0;i<52;i++)
printf("%5s of %-8s%c",wdeck[i].face,wdeck.[i].suit,(i+1)%2?'\t':'\n');
}
E:\C语言作业\结构体\314\314.cpp(10) : error C2236: unexpected 'struct' 'card'
E:\C语言作业\结构体\314\314.cpp(56) : error C2059: syntax error : '['
Error executing cl.exe.

搜索更多相关主题的帖子: 洗牌 结构体 
2007-03-14 11:34



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-124144-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.102068 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved