So I have a poker type program where it should shuffle and deal a deck of cards using arrays of pointers. I have to write a function that uses a pointer(s) to determine if the hand contains an Ace. If I can understand this one, I'd be able to do the rest with no problems. I was told to do what I did with int decks, int dealt, int the_hand, but I keep getting errors. I've been trying everything I could think of, but no luck. Am I even in the right direction?
Also, I read the book, reviewed my teachers notes, and even tried Googling this, but none of them helped. My teacher gave me a hint, but won't say anything else " Use the same parameter list as the deal function".
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define SUITS 4
#define FACES 6
#define CARDS 24
#define THE_HAND 5
// prototypes
void shuffle(unsigned int wDeck[][FACES]); // prototype to shuffle deck
void deal(unsigned int wDeck[][FACES], const char *wFace[],
const char *wSuit[]); // dealing doesn't modify the arrays
int has_ace(int *the_hand);
int main(void) {
// initialize deck array
unsigned int deck[SUITS][FACES] = {0};
int *decks = malloc(CARDS * sizeof(int));
int dealt = 0; //number of cards taken from deck
int *the_hand = NULL; //current hand
srand(time(NULL)); // seed the RNG
shuffle(deck); // shuffle the deck
if (has_ace(the_hand)){
printf("The hand has Jack\n");
}
else{
printf("The hand has no Jack\n");
}
// initialize suit array
const char *suit[SUITS] = {"Hearts", "Diamonds", "Clubs", "Spades"};
// initialize face array
const char *face[FACES] = {"Ace", "Nine", "Ten","Jack", "Queen", "King"};
deal(deck, face, suit); // deal the deck
};
int has_ace(int *the_hand){
for (int i = 0; i < THE_HAND; i++){
if (the_hand[i] == "ACE"){
return 1; //true
}
}
return 0; //false
}
// shuffle cards in deck
void shuffle(unsigned int wDeck[][FACES]) {
// for each of the cards, choose slot of deck randomly
for (size_t card = 20; card <= CARDS; card++) {
size_t row;
size_t column;
// choose new random location until unoccupied slot found
do {
row = rand() % SUITS;
column = rand() % FACES;
} while (wDeck[row][column] != 0);
// place card number in chosen slot of deck
wDeck[row][column] = card;
}
}
// deal cards in deck
void deal(unsigned int wDeck[][FACES], const char *wFace[], const char *wSuit[]) {
// deal each of the cards
for (size_t card = 20; card <= CARDS; card++) {
// loop through rows of wDeck
for (size_t row = 0; row < SUITS; row++) {
// loop through columns of wDeck for current row
for (size_t column = 0; column < FACES; column++) {
// if slot contains current card, display card
if (wDeck[row][column] == card) {
printf("%5s of %-8s%c",
wFace[column], wSuit[row],
card % 2 == 0 ? '\n' : '\t');
} // end if
} // end column for loop
} // end row for lop
} // end card for loop
} // end deal function
Things I've tried:
int has_ace(int *the_hand){
for (int i = 0; i < THE_HAND; i++){
if (the_hand[i] == "Ace"){
return 1; //true
}
}
return 0; //false
}
int has_ace(int *the_hand){
for (int i = 0; i < THE_HAND; i++){
if (the_hand[i] == wDeck[Ace][FACES]){
return 1; //true
}
}
return 0; //false
}
int has_ace(int *the_hand){
for (int i = 0; i < THE_HAND; i++){
if (the_hand[i] == wFace[Ace]){
return 1; //true
}
}
return 0; //false
}
Errors I get:
/home/zombieknight93/Desktop/School/Unix/Programs/hw5/card_shuffle_deal.c: In function ‘has_ace’:
/home/zombieknight93/Desktop/School/Unix/Programs/hw5/card_shuffle_deal.c:48:25: warning: comparison between pointer and integer if (the_hand[i] == "Ace"){