how to fix the snytax error: identifier 'column'

this is my code

#include<stdio.h>

void main()
{
int player=0;
int winner=0;
int choice=0;
int row=0;
int column=0;
int line=0;

char board[3][3]=
{
{'1','2','3'},
{'4','5','6'},
{'7','8','9'}
};

printf("Let's start the Tic Tac Toe Game!\n");

int k;
for(k=0;k<9&&winner==0;k++)
{
{
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=k%2+1;

do
{
printf("Player %d\n",player);
printf("Please choose a position to place your %c:",(player==1)?'X':'O');
scanf("%d",&choice);

}

column=choice%3;
row=--choice/3;

while(choice<0 || choice>9 || board[row][column]>'9');
{
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("How boring,it is a draw\n");
else
printf("Congratulation, Player %d, you are the winner!\n",winner);



}


===============================================================================

anyone can help me solve this syntax error: identifier 'column'??
thank you!!
You've got:

1
2
3
4
5
6
7
do
 {
 printf("Player %d\n",player);
 printf("Please choose a position to place your %c:",(player==1)?'X':'O');
 scanf("%d",&choice);

 }


but the correct syntax is:

do { /* code */ } while (condition);

I would also suggest that you declare variables as and when you require them, rather than all up front. Further if you are declaring a bunch of variables of the same type you can do:

 
   int player(0), winner(0), choice(0), row(0), column(0), line(0);


When using for (...) loop you can declare the index inside the for (...):

1
2
3
4
   for (int k = 0; k < 9 && winner == 0; ++k)
   {
       // code
   }


HTH
anyone can help me solve this syntax error: identifier 'column'??

I'm sure that's not the entirety of the error message. Why have you arbitrarily cut the message down to only part of it?

Please use code tags to make your code readable.

@MikeyBoy - the line where he assigns (if code tags were used I could tell you the line number) a value to the 'column' variable is after the do{} block. What the code is complaining about is the lack of the while(condition); of the do...while block.
Last edited on
Topic archived. No new replies allowed.