i need to write a program that
1) Prompts a user to enter the current state of a board.
2) Print out the board
3) Determines if there is a winner, and, if there is, who it is.
this is what i have, and nothing happens when i use it
Code:#include<stdio.h>
int
main(void)
{
char tic_tac_toe[3][3] =
{{' ', ' ', ' '}, {' ', ' ', ' '}, {' ', ' ', ' '}};
}
void enter_symbol(char tic_tac_toe[][2], int player)
{
int row, col;
while(1){
printf("Where would u like to enter symbol\n", player);
scanf("%d", &row);
scanf("%d", &col);
if (tic_tac_toe[row][col]==' ')
{
if (player == 1)
tic_tac_toe[row][col]=='x';
else
tic_tac_toe[row][col]='o';
break;
}
else
printf("Position already taken\n");
}
}
void print_board(char tic_tac_toe[][2])
{
printf("\n %c|%c|%c\n -----\n", tic_tac_toe[0][0], tic_tac_toe[0][1], tic_tac_toe[0][2]);
printf(" %c|%c|%c\n -----\n", tic_tac_toe[1][0], tic_tac_toe[1][1], tic_tac_toe[1][2]);
printf(" %c|%c|%c\n", tic_tac_toe[2][0], tic_tac_toe[2][1], tic_tac_toe[2][2]);
}
int has_won (char tic_tac_toe[][2]){
if (tic_tac_toe[0][0] == tic_tac_toe[0][1] &&
tic_tac_toe[0][1] == tic_tac_toe[0][2]){
printf("%c has won!\n", tic_tac_toe[0][0]);
return (1);
}
else if (tic_tac_toe[1][0] == tic_tac_toe[1][1] &&
tic_tac_toe[1][1] == tic_tac_toe[1][2]){
printf("%c has won!\n", tic_tac_toe[1][0]);
return (1);
}
else if (tic_tac_toe[2][0] == tic_tac_toe[2][1] &&
tic_tac_toe[2][1] == tic_tac_toe[2][2]){
printf("%c has won!\n", tic_tac_toe[2][0]);
return (1);
}
else if (tic_tac_toe[0][0] == tic_tac_toe[1][0] &&
tic_tac_toe[1][0] == tic_tac_toe[2][0]){
printf("%c has won!\n", tic_tac_toe[0][0]);
return (1);
}
else if (tic_tac_toe[0][1] == tic_tac_toe[1][1] &&
tic_tac_toe[1][1] == tic_tac_toe[2][1]){
printf("%c has won!\n", tic_tac_toe[0][1]);
return (1);
}
else if (tic_tac_toe[0][2] == tic_tac_toe[1][2] &&
tic_tac_toe[1][2] == tic_tac_toe[2][2]){
printf("%c has won!\n", tic_tac_toe[0][2]);
return (1);
}
else if (tic_tac_toe[0][0] == tic_tac_toe[1][1] &&
tic_tac_toe[1][1] == tic_tac_toe[2][2]){
printf("%c has won!\n", tic_tac_toe[0][0]);
return (1);
}
else if (tic_tac_toe[0][2] == tic_tac_toe[1][1] &&
tic_tac_toe[1][1] == tic_tac_toe[2][0]){
printf("%c has won!\n", tic_tac_toe[0][2]);
return (1);
}
else
printf("Tie game\n");
return(0);
}