Hi everyone!
I trying to write a code for tic tac toe game,trying to form the grid and place the character in the specified location.The problem is that,for example when I try to place the character in 2nd row,2nd col and if 2nd row and 3rd col already has a char,it get shifted out of the grid.Could you please help me understand this better,I am trying to change spaces but it's not helping.
Code:
#include<stdio.h>
int grid[3][3];
void block()
{
int row,col;
printf("\t\ttic tac toe\n");
for(row=1;row<=3;row++)
{
printf("\t\t___________________\n");
printf("\t\t| | | |\n");
for(col=1;col<=3;col++)
{
if(grid[row][col]==1)
{
if(col==1)
printf("\t\t 1");
else if(col==2)
printf("\t\t 2");
else
printf("\t\t 3");
}
}
printf("\n");
printf("\t\t| | | |\n");
}
printf("\t\t___________________\n");
}
int main()
{
int i,row,col;
block();
for(row=1;row<=3;row++)
{
for(col=1;col<=3;col++)
grid[row][col]=0;
}
for(i=0;i<9;i++)
{
printf("enter the row no.\n");
scanf("%d",&row);
printf("enter the col no\n");
scanf("%d",&col);
grid[row][col]=1;
block();
}
return 0;
}