cant get it to play crrectly

What is my error?

include <stdio.h>
void displayBoard(char [3][3]);

int main()

{
int player = 0;
int winner = 0;
int choice = 0;
int row = 0;
int column = 0;
int line = 0;

char board [3][3] = {
{' ',' ',' '},
{' ',' ',' '},
{' ',' ',' '}};

for (int i = 0; i<9 && winner==0; i++)
{
printf("\n\n");
printf(" %c | %c | %c\n", board[0][0], board[0][1], board[0][2]);
printf("---|---|---\n");
printf(" %c | %c | %c\n", board[1][0], board[1][1], board[1][2]);
printf("---|---|---\n");
printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]);

player = i%2 + 1;

do
{
printf("\nPlayer %d, Enter "
"where you want to place your %c: ",
player,(player==1)?'X':'O');
scanf("%d", &choice);

row = --choice/3;
column = choice%3;
}while(choice<0 || choice>9 || board [row][column]>' ');

board[row][column] = (player == 1) ? 'X' : 'O';

if((board[0][0]==board[1][1] && board[0][0]==board[2][2]) ||
(board[0][2]==board[1][1] && board[0][2]==board[2][0]))
winner = player;
else

for(line = 0; line <=2; line++)
if((board[line][0]==board[line][1] && board[line][0]==board[line][2])||
(board[0][line]==board[1][line] && board[0][line]==board[2][line]))
winner = player;

}

printf("\n\n");
printf(" %c | %c | %c\n", board[0][0], board[0][1], board[0][2]);
printf("---|---|---\n");
printf(" %c | %c | %c\n", board[1][0], board[1][1], board[1][2]);
printf("---|---|---\n");
printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]);

if(winner==0)
printf("The game is a draw\n");
else
printf("Player %d wins!!\n", winner);

return 0;

}

We would hope that you will tell us what is the problem with the program - then we can focus on a specific spot within your program, to look for errors.

Saves a lot of time, that way, and gives you a chance to develop some better problem solving skills of your own - debugging your program is a skill set that you need to practice to be any good at it.

ALWAYS use code tags around your C code, so it retains it's C indentations! Those are SO important to show the logic in the code, instead of just html (forum) text formatting - which makes code look like something the cat threw up yesterday. :(

Just highlight your code, and click on "Code" in the header of the edit window - done!

I really like the overall design of this program - it's wonderfully compact. Just hard to read through as C code, when it's formatted this way.

Can you repost it and use the code tags, and tell us what the problem is that we should focus on?

Thanks, and welcome to the forum! ;)

commented: nicely said +9
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.