I'm trying to create a grid of characters, and for this example am using a 3by 3 grid. I am using two for loops to assign from a separate one dimensional array of characters, but the final value in each row is always equal to the first value of the next, but can't understand why. Is something wrong with my calculation of row and col?
char text[8] = "abcdefghi";
char grid[2][2];
int i,j;
for(i=0; i<=8; i++)
{
char c = text[i];
int row = i/3;
int col = i%3;
printf("%c row=%d col=%d i=%d\n", c, row, col, i);
grid[row][col] = c;
}
printf("------\n");
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
printf("%c row=%d col=%d \n", grid[i][j], i, j);
}
}