[Solved] compile errors when trying to use struct in c


struct player only contains name and col. It doesn’t contain a BOOLEAN member.

You could add such a member to it and have that member indicate whether the player is current. However that would be a bad design (because it is tedious to code and there are better options).

Instead, have another variable that indicates which player is current. One way would be to point directly to the player:

struct player *current_player = &p1;
// ...
player_turn(current_player, board);

// make next player be current
current_player = &p2;

Alternatively you could store an int or similar which indicates which of the players is current and then include some logic to get the player based on that number. This would be easier if the players were stored in an array, e.g.

struct player players[4];
int current_player = 0;
// ...
player_turn(&players[current_player], board);

// make next player be current
++current_player;
if ( current_player > 3 )
    current_player = 0;

solved compile errors when trying to use struct in c