I'm trying to improve my lousy C skills so I'm writing a tic tac toe program. It's only in its first steps but I would like to be able to print a board before going into the whole algorithms of the game itself. I'm planning to use 1 for x and 0 for circle in order to be able to use sums later. I'm working with gcc (ubuntu) and am getting this error:
xo.c:11:3: error: (near initialization for ‘board[0]’)
xo.c:11:3: error: excess elements in char array initializer
xo.c:11:3: error: (near initialization for ‘board[0]’)
xo.c:11:3: error: excess elements in char array initializer
xo.c:11:3: error: (near initialization for ‘board[1]’)
xo.c:11:3: error: excess elements in char array initializer
xo.c:11:3: error: (near initialization for ‘board[1]’)
xo.c:11:3: error: excess elements in char array initializer
xo.c:11:3: error: (near initialization for ‘board[2]’)
xo.c:11:3: error: excess elements in char array initializer
xo.c:11:3: error: (near initialization for ‘board[2]’)
I would like to initiate a 2 dimensional array of 3x3 for the board. I don't understand why is there an excess, I initialized a [3][3] and entered 9 elements. Here is the code I've written:
#include<stdio.h>
/***** Create two dimensional array full of blank spaces
1 marks the X , 0 marks the circle.
Let use enter coordinates (line and coloumn) for placing the 1 (x) and automatically print the board with the computers' move.
*****/
int i = 0;
int j = 0;
void main() {
char board[3][3] = {
{" " , " " , " "} , {" " , " " , " "} , {" " , " " , "t"}
};
for(i=0 ; i<3 ; i++) {
for(j=0 ; j<3 ; j++) {
printf("%c " , board[i][j]);
}
printf("\n");
}
}