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

我写个用结构体洗牌的,有两个报错不会改
#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
PcrazyC
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:5652
专家分:0
注 册:2006-10-20
得分:0 

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

typedef struct card Card;
改为
typedef struct
{
char *face;
char *suit;
}Card;

[此贴子已经被作者于2007-3-14 11:47:47编辑过]


雁无留踪之意,水无取影之心
2007-03-14 11:47
PcrazyC
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:5652
专家分:0
注 册:2006-10-20
得分:0 
wdeck.[i].suit这是什么,我想你应该知道了

雁无留踪之意,水无取影之心
2007-03-14 11:48
无玩过界
Rank: 1
等 级:新手上路
威 望:2
帖 子:246
专家分:0
注 册:2007-2-20
得分:0 
以下是引用wandison在2007-3-14 11:34:30的发言:

我写个用结构体洗牌的,有两个报错不会改
#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');
}/*wdeck.[i].suit写错了*/
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 12:35



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




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

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