2

Learning C and need to populate array of five struct elements but I can't seem to figure out how to pass the struct array to a function and I keep getting error:

error: conflicting types for 'dealFiveHand'

Here is the code:

#define HAND_SIZE 5

void dealFiveHand(struct Card *wHand[]);

struct Card {
    char suit;
    char face;
};

int main(void)
{
    struct Card *hand[HAND_SIZE];
    dealFiveHand(hand); 
}

void dealFiveHand(struct Card *wHand[])
{
   ...
}

Do I need to define and initialize a pointer and then pass that pointer to the function?

2
  • Is that the complete error message? There's nothing else? No informational notes or anything else printed as part of the error? Commented Nov 6, 2016 at 4:49
  • Please show the full error message. Please show the exact code as a minimal reproducible example (what you have is close already so just make it the actual code with the actual error message including line numbers). Commented Nov 6, 2016 at 4:49

2 Answers 2

4

At least you need to move the definition of struct Card BEFORE function dealFiveHand prototype - that way the function knows about the type of its parameter.

struct Card {
    char suit;
    char face;
};

void dealFiveHand(struct Card *wHand[]);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. Makes sense. Not sure how I was missing it.
3

You are referring Card, before defining it. Declare it first, before referring it, as a argument of your function dealFiveHand()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.