我将一张“洗牌”程序的代码从一本书复制到我的CodeBlocks编辑器并尝试运行它。它打开DOS框,一秒钟后我收到错误,说“filename.exe”已停止工作。 我已经检查了两次代码并且没有错误。你们能帮助我吗? 以下是代码:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<time.h>
struct card{
const char *face;
const char *suit;
};
typedef struct card Card;
void filldeck(Card * const wDeck, const char *wFace[],const char *wSuit[]);
void shuffle(Card * const wDeck);
void deal(const Card * const wDeck);
int main(void){
Card deck[52];
const char *face[]={"Ace","Deuce","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King"};
const char *suit[]={"Hearts","Diamonds","Clubs","Spades"};
srand(time(NULL));
fillDeck(deck,face,suit);
shuffle(deck);
deal(deck);
return 0;
}
void fillDeck(Card * const wDeck, const char *wFace[],const char *wSuit){
int i;
for(i=0;i<=5;i++){
wDeck[i].face=wFace[i%13];
wDeck[i].suit=wSuit[i/13];
}
}
void shuffle(Card * const wDeck){
int i,j;
Card temp;
for(i=0;i<=5;i++){
j=rand()%52;
temp=wDeck[i];
wDeck[i]=wDeck[j];
wDeck[j]=temp;
}
}
void deal(const Card * const wDeck){
int i;
for(i=0;i<=5;i++){
printf("%5s of %-8s%s",wDeck[i].face,wDeck[i].suit,(i+1)%4 ? " ": "\n");
}
}