the player moves has too few arguments which I have no clue. Also I haven't finished the main function yet because I also have errors there......
Code:
#include <stdio.h>
void info()
{
printf("TIC-TAC-TOE\nWritten by me\n");
printf("Your Symbol 'x'");
printf("Computer Symbol 'o'");
}
/*initialize board*/
void init(char cell[])
{
int i;
for (i=0; i<9; i++) cell[i] = ' ';
}
/*print gameboard */
void gameBoard(char cell[])
{
printf("\n %c | %c | %c \n", cell[0], cell[1], cell[2]);
printf("---|---|---\n");
printf(" %c | %c | %c \n", cell[3], cell[4], cell[5]);
printf("---|---|---\n");
printf(" %c | %c | %c \n\n", cell[6], cell[7], cell[8]);
}
/*player moves*/
void userMove(char cell[])
{
int i;
gameBoard();
printf("Your Move (0-8): ");
scanf("%d", &i);
while ( i < 0 || i > 8 )
{ printf("Invalid Move"); userMove(); }
}
void computerMove(char cell[])
{
scanf( cell[0]=' ' );
scanf( cell[1]=' ' );
scanf( cell[2]=' ' );
scanf( cell[3]=' ' );
scanf( cell[4]=' ' );
scanf( cell[5]=' ' );
scanf( cell[6]=' ' );
scanf( cell[7]=' ' );
scanf( cell[8]=' ' );
}
/* Check for a winning line - diagonals first */
char checkWinner (char cell[])
{
if(cell[0] == cell[1] == cell[2])
{
if(cell[0] != ' ')
{
return cell[0];
} else return ' ';
} else if(cell[3] == cell[4] == cell[5])
{
if(cell[3] != ' ')
{
return cell[3];
} else return ' ';
} else if(cell[6] == cell[7] == cell[8])
{
if(cell[6] != ' ')
{
return cell[6];
} else return ' ';
} else if(cell[0] == cell[3] == cell[6])
{
if(cell[0] != ' ')
{
return cell[0];
} else return ' ';
} else if(cell[1] == cell[4] == cell[7])
{
if(cell[1] != ' ')
{
return cell[1];
} else return ' ';
} else if(cell[2] == cell[5] == cell[8])
{
if(cell[2] != ' ')
{
return cell[2];
} else return ' ';
} else if(cell[0] == cell[4] == cell[8])
{
if(cell[0] != ' ')
{
return cell[0];
} else return ' ';
} else if(cell[2] == cell[4] == cell[6])
{
if(cell[2] != ' ')
{
return cell[2];
} else return ' ';
} else return 'd';
}
int main()
info();
init();