Alternating turns in C code for 2 player game
Hi
I am interested in ways to code taking turns for 2 player board games & came across this code using loops on the site here:For, While and Do While Loops in C - Cprogramming.com
I am trying to code an example & have this so far (but it is very limited & probably unsound).
Code:
#include <stdio.h>
#define TRUE 1
int someone_has_won(){
return 0;
}
int someone_wants_to_quit(){
return 0;
}
int take_turn(){
return 0;
}
int main(int argc, char **argv)
{
int player1;
int player2;
int true;
while(true)
{
if (someone_has_won() || someone_wants_to_quit() == TRUE)
{break;}
take_turn(player1);
if (someone_has_won() || someone_wants_to_quit() == TRUE)
{break;}
take_turn(player2);
}
return 0;
}
which compiles but with these warnings:
Quote:
gcc -Wall -c "turns.c" ()
turns.c: In function 'main':
turns.c:59:14: warning: 'player1' may be used uninitialized in this function [-Wuninitialized]
turns.c:62:14: warning: 'player2' may be used uninitialized in this function [-Wuninitialized]
turns.c:55:7: warning: 'true' is used uninitialized in this function [-Wuninitialized]
Compilation finished successfully.
Can someone please help me expand it further into code that would work properly? I'm very grateful for helpful replies-thanks