The array degrades to the original pointer to the first element of the array. So you can do something more like this:
#define HAND_SIZE 5 struct Card { char suit; char face; }; void printHandResults(struct Card *hand); int main(void) { struct Card hand[HAND_SIZE]; ... printHandResults(hand); } void printHandResults(struct Card *hand) { for (int i = 0; i < HAND_SIZE; ++i) {
As an alternative:
#define HAND_SIZE 5 struct Card { char suit; char face; }; void printHandResults(struct Card *hand, int numInHand); int main(void) { struct Card hand[HAND_SIZE]; ... printHandResults(hand, HAND_SIZE); } void printHandResults(struct Card *hand, int numInHand) { for (int i = 0; i < numInHand; ++i) {
Alternatively, create a new typedef for the map array, and then you can create variables and pointers of this type:
#define HAND_SIZE 5 struct Card { char suit; char face; }; typedef struct Card Hand[HAND_SIZE]; void printHandResults(Hand *hand); int main(void) { Hand hand; ... printHandResults(&hand); } void printHandResults(Hand *hand) { for (int i = 0; i < HAND_SIZE; ++i) {
source share