我写个用结构体洗牌的,有两个报错不会改
#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.
----------------解决方案--------------------------------------------------------
struct card{
char *face;
char *suit;
}
typedef struct card Card;
改为
typedef struct
{
char *face;
char *suit;
}Card;
[此贴子已经被作者于2007-3-14 11:47:47编辑过]
----------------解决方案--------------------------------------------------------
wdeck.[i].suit这是什么,我想你应该知道了
----------------解决方案--------------------------------------------------------
我写个用结构体洗牌的,有两个报错不会改
#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.
----------------解决方案--------------------------------------------------------