Occlude Occlude - 1 year ago 94
C Question

c - expecting struct pointer but getting struct and the reverse

I am attempting to call on function "play game" from main, with play game having input type 'struct player'. However, I am getting error:

game.h:18:17: note: expected ‘struct player *’ but argument is of type ‘struct player’
struct player * play_game(struct player * first, struct player * second);
reversi.c:47:4: error: incompatible type for argument 1 of ‘play_game’
*winner = play_game( first , second );

With the error being thrown out for argument 2.

When I switch the argument type to being a pointer I get:

reversi.c:47:12: error: incompatible types when assigning to type ‘struct player’ from type ‘struct player *’
*winner = play_game( first , second );

I've looked around, but there doesn't seem to be much on this, and it's usually related to the .h file itself, while I am almost certain that the error must involve the line: "*winner = play_game( first , second );" (the other lines here were provided)

I've also tried changing all the pointers, even when to the point that if it had worked I would have been lost, but haven't gotten anywhere except getting variations on the same error.

I've trimmed the code down for posting, but it does still produce the same error.

#include <stdio.h>
#include <stdlib.h>

#define NAMELEN 20

struct player * play_game(struct player * first, struct player * second) ;

enum cell

struct player
char name[NAMELEN + 1];
enum cell token;
unsigned score;

int main(void)
struct player first, second, *winner = NULL;
enter code here
*winner = play_game( first , second );


struct player * play_game(struct player * first, struct player * second)

return first;


Thank you in advance for any help you can give.

Answer Source

The function call musts to look like

winner = play_game( &first , &second );
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download