Code:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#define DECKSIZE 52
#define VALUE 9
#define FACE 4
#define TRUE
#define FALSE
typedef struct {
int value;
char suit[10];
char name[10];
}Card;
Card cards[DECKSIZE];
char *faceName[13][10]={"two","three","four","five","six","seven","eight","nine",
"ten","jack","queen","king","ace"};
char *suitName[4][10]={"spades","diamonds","hearts","clubs"};
void printDeck(){
int i;
for(i=0;i<DECKSIZE;i++){
printf("%s of %s \n",cards[i].name,cards[i].suit);
if((i+1)%13==0 && i!=0) printf("--------------------\n\n");
}
}
void shuffleDeck(){
srand(time(NULL));
int this;
int that;
Card temp;
int i;
for (i=0;i<100;i++){
int j = i+ rand()%(100-i);
this=rand()%DECKSIZE;
that=rand()%DECKSIZE;
while(this==that)that=rand()%(52+1);
//printf("shuffle card%d with card %d\n", this, that);
temp=cards[this];
cards[this]=cards[that];
cards[that]=temp;
}
}
int main(){
int suitCount=0;
int faceCount=0;
int i;
srand(time(NULL));
for(i=0;i<DECKSIZE;i++){
if(faceCount<9){
cards[i].value=faceCount+2;
}else{
cards[i].value=10;
}
cards[i].suit,suitName[suitCount];
cards[i].name,faceName[faceCount++];
if(faceCount==13){
cards[i].value=11;
suitCount++;
faceCount=0;
}
}
int numCards=0;{
int sumHand(Card hand[12], int numCards());
int i;
int rval=0;
for(i=0;i<numCards;i++){
rval=cards[i].value;
return rval;
}
}
//printDeck();
//shuffleDeck();
//printDeck();
{
int nextCard=0;
int numCardsDealer=0;
Card dealerhand[12];
int stop;
int numCards=0;
while(!stop){
while(sumCards(dealerhand,numCards)<=17){
dealerhand[numCards]=cards[nextCard++];
printf("%s of %s value=%d\n", dealerhand[numCards].name,numCards++);
}
}
int finalvalue= sumCards(dealerhand,numCards);
if(finalvalue>21) printf("BUSTED!");{
printf("Press one to stop or zero to keep going:");
scanf("%d", &stop);}
{
return 0;
}
}}
i fixed all that with the current changes and it compliles but i get a segmentation fault:
a.out
of (null) value=7448132
Segmentation fault
why??????