Hi guys, I am creating a checkers board game for my assignment which is due soon. The problem is the char 'X' doesn't go into the array. Any idea? Have been searching for error for almost an hour but still no clue.

Code:
``` void gameboard(char board)
{

int x, y;

for(x=0; x<16; x++)
{
for(y=0;y<8;y++)
{
if(x % 2 == 0)
{
printf(" %c ",board[x][y]);
}
else{
printf("| %c |",board[x][y]);
}
}
printf("\n");
}

}

void character(char board)
{
int x,y;

for(x=0;x<16;x++){
for(y=0;y<8;y++){

if(x<6){

if(x%2 == 0){
if(x%2 == 0){
board[x][y] = ' ';

}
}

if(x%2 == 1){
if(y%2 == 0){
board[x][y] = 'O';
}
if(y%2 ==1){
board[x][y]= ' ';

}
}

if(x==3){
if(y%2 == 1){
board[x][y] = 'O';
}
if(y%2 == 0){
board[x][y] = ' ';
}
}
}

if((x==6)||(x==7)||(x==8)||(x==9)){
board[x][y] = ' ';
}

if(x>9)
{

if(x%2 == 0){
if(x%2 == 0){
board[x][y] = 'X';

}
if(y%2 == 0){
board[x][y] = ' ';
}

}

if(x%2 == 1){
if(y%2 == 1){
board[x][y] = ' ';
}

}
if(x==12){
if(y%2 == 0){
board[x][y] = 'X';
}
if(y%2 == 1){
board[x][y] = ' ';
}

}

}

}
}
}``` 2. Well aside from the poor indentation, it seems fine.
Code:
```#include <stdio.h>
#include <string.h>

void gameboard(char board)
{
int x, y;

for (x = 0; x < 16; x++) {
for (y = 0; y < 8; y++) {
if (x % 2 == 0) {
//!! it's not helpful when different rows have different
//!! numbers of chars printed
printf(" %c ", board[x][y]);
} else {
printf("| %c |", board[x][y]);
}
}
printf("\n");
}
}

void character(char board)
{
int x, y;

for (x = 0; x < 16; x++) {
for (y = 0; y < 8; y++) {
if (x < 6) {
if (x % 2 == 0) {
if (x % 2 == 0) {
board[x][y] = ' ';
}
}
if (x % 2 == 1) {
if (y % 2 == 0) {
board[x][y] = 'O';
}
if (y % 2 == 1) {
board[x][y] = ' ';
}
}
if (x == 3) {
if (y % 2 == 1) {
board[x][y] = 'O';
}
if (y % 2 == 0) {
board[x][y] = ' ';
}
}
}

if ((x == 6) || (x == 7) || (x == 8) || (x == 9)) {
board[x][y] = ' ';
}

if (x > 9) {
if (x % 2 == 0) {
if (x % 2 == 0) {
board[x][y] = 'X';
}
if (y % 2 == 0) {
board[x][y] = ' ';
}
}
if (x % 2 == 1) {
if (y % 2 == 1) {
board[x][y] = ' ';
}
}
if (x == 12) {
if (y % 2 == 0) {
board[x][y] = 'X';
}
if (y % 2 == 1) {
board[x][y] = ' ';
}
}
}
}
}
}

int main()
{
char board = { { 0 } };
// any dots printed later mean character() didn't do it's job properly
memset(board,'.',sizeof(board));
character(board);
gameboard(board);
return 0;
}

My output
\$ ./a.out
00=
01=| O ||   || O ||   || O ||   || O ||   |
02=
03=|   || O ||   || O ||   || O ||   || O |
04=
05=| O ||   || O ||   || O ||   || O ||   |
06=
07=|   ||   ||   ||   ||   ||   ||   ||   |
08=
09=|   ||   ||   ||   ||   ||   ||   ||   |
10=    X     X     X     X
11=| . ||   || . ||   || . ||   || . ||   |
12= X     X     X     X
13=| . ||   || . ||   || . ||   || . ||   |
14=    X     X     X     X
15=| . ||   || . ||   || . ||   || . ||   |```
But then again, it's not clear what you would call success.

Why do you need a 16x8 board for checkers?
You're just polluting a lot of code with a lot of x%2 nonsense, where the extra spacing only really matters in the display routine. You don't need "board" to be 16x8 just to have a blank line printed between the rows of the board. It should be 8x8 and just hold the pertinent data. The blank lines can be added when it's printed. If you need to add a marker in the blank rows to indicate a particular piece, the position of that marker can be saved in two ints (e.g., markrow, markcol) and passed to the print function.

Your board initialization function can be simplified (even assuming an 8x8 board). Fist note that, according to Salem's run of your program, not only are the X's misplaced, but the O's are on the wrong squares too. The top left square should be blank (it's a "light square").

To simplify the process, note that indexing the rows and columns by row % 2 and col % 2 shows that the "dark squares" (the ones that the pieces play on) occur when row % 2 != col % 2. The light squares occur when they're equal.

Code:
````  0 1 0 1 0 1 0 1
0    .   .   .   .
1  .   .   .   .
0    .   .   .   .
1  .   .   .   .
0    .   .   .   .
1  .   .   .   .
0    .   .   .   .
1  .   .   .   .```
(This assumes numbering rows from top to bottom. If they're numbered from bottom to top then the comparisons are reversed.) 4. Hi guys, thanks for the feedback. The reason why I used 16x8 board because I wanted to insert hyphen '_' on top and bottom of the character starting from the first top left 'X' and move the hyphen to select the character that I want. By the way, I am new to programming, I am here to learn.  5. But that hyphen cursor can be added by the display routine, which prints each row of the board on alternate lines of the display. Popular pages Recent additions 2d array, array, error, idea, searching 