I cant seem to figure out how to set my printf statement to be able to print all elements of struct array that I'm passing to print function.
When I try to compile I get warnings:
format specifies type 'char *' but the argument has type 'char' [-Wformat]
I tried casting but still get an error.
When I run the program I just get:
Segmentation fault: 11
Here is the code:
struct Card {
char suit;
char face;
};
int main(void)
{
...
struct Card *hand[HAND_SIZE];
dealHand(deck, face, suit, hand); //deal the deck
printHand(hand);
}
void dealHand(unsigned int wDeck[][FACES], const char *wFace[], const char *wSuit[], struct Card *wHand[])
{
unsigned int c = 0;
for (size_t card = 1; card <= HAND_SIZE; ++card) {
for (size_t row = 0; row < SUITS; ++row) {
for (size_t column = 0; column < FACES; ++column) {
if (wDeck[row][column] == card){
struct Card aCard;
aCard.face = wFace[column];
aCard.suit = wSuit[row];
wHand[0] = &aCard;
c = c + 1;
}
}
}
}
}
void printHand(struct Card *wHand[]) {
for (unsigned i = 0; i < HAND_SIZE; ++i) {
printf("%c%c\n", wHand[i]->face, wHand[i]->suit);
}
}
How can I print array of structs?
Edit: I replaced %s with %c but now getting warning:
incompatible pointer to integer conversion assigning to 'char' from 'const char *' [-Wint-conversion]
aCard.face = wFace[column];
New to pointers and not sure how to go about solving this one.
struct. try with%c