In my blackjack game the integer value of ace is fixed to 11 but in those cases when one player gets an ace but the total value of the cards in her hand is going to be higher then 21 I want the integer value of ace to be 1.
void deal(const Card * const Deck, int value, int size, int size_1, int size_2){
int i, j, length;
char anotherCard[2];
char name1[30];
char name2[30];
int valueName1 = 0, valueName2 = 0, valueDealer = 0;
printf("Name player one > ");
scanf("%s", name1);
printf("Name player two > ");
scanf("%s", name2);
printf("\nWelcome %s and %s, lets begin!\n\n", name1, name2);
getchar();
while (valueName1 < 21 || valueName2 < 21 || valueDealer < 17){
printf("%s's card:\n", name1);
for (i = 0; i < size; i++){
printf("%5s of %-8s%c", Deck[i].decks, Deck[i].suits, (i + 1) % 2 ? '\t' : '\n');
if (valueName1 > 21 && Deck[i].value == 11){
Deck[i].value = 1; //error on this line
valueName1 += Deck[i].value;
printf("value > %d\n", valueName1);
}
else{
printf("value > %d\n", valueName1);
}
}
int main(void){
Card allCards[52];
Card cardValue[52];
char *suitname[] = { "spades", "hearts", "diamonds", "clubs" };
char *deckname[] = { "ace", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "jack", "queen", "king" };
int cardvalue[] = { 11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10 };
void fillDeck(Card * const Deck, const char *suit[], const char *deck[], const int value[]){
int s;
for (s = 0; s < 52; s++){
Deck[s].suits = deck[s % 13];
Deck[s].decks = suit[s / 13];
Deck[s].value = value[s % 13];
}
return;
}
my struct:
typedef struct card{
const char *suits;
const char *decks;
int value;
};
error message: error C2166: l-value specifies const object
You declare Deck
as
const Card * const Deck
That means Deck
is a constant pointer to constant data, i.e. you can't change the pointer and (more importantly) you can't change the data it points to. You need to drop the first const
to make it work
Card * const Deck