I am trying to take the values entered into the array and populate the display(board) function in those coordinates. I can't figure out how to populate the display with 'Q' in the correct coordinates.
Code:
#include <stdio.h>
#include <ctype.h>
#define SIZE 8 /* Size of board*/
/* function prototype */
void display(char board[] [SIZE]);
int valid_moves(char board[] [SIZE], int moves[] [SIZE], char player);
void main()
{
char board [SIZE] [SIZE] ={ 0 }; /* The board*/
int moves[SIZE] [SIZE] ={0}; /* valid moves */
int row = 0;
int col = 0;
char queenie = 'Q'; /* user selection*/
char y =0; /* column letter*/
int x =0; /* row number*/
char player = 'Q';
/* empty all the squares */
for(row = 0; row < SIZE; row++)
for(col = 0; col < SIZE; col++)
board[row] [col] = ' ';
display(board); /* display the board */
fflush(stdin); /*flush the buffer: keyboard--stdin*/
printf("please enter the row and column to place the queen:");
scanf("%d%c", &x, &y);
printf("%d %c\n",x ,y);
board[x][y]='Q';
display(board);
if(x<0 && y<0 || x>SIZE && y>SIZE)
{
printf(" That is an invalid entry!\n");
}
/*else &x*/
}
/* display board funtion definition*/
void display(char board[] [SIZE])
{
int row = 0; /* row index */
int col = 0; /* col index */
char col_label = 'a'; /* column label */
printf("\n "); /*start top line */
for(col = 0; col<SIZE; col++)
printf(" %c", col_label+col); /* display the top line*/
printf("\n"); /*end of top line*/
/*display the intermediate rows*/
for(row = 0; row < SIZE; row++)
{
printf(" +");
for(col = 0; col<SIZE; col++)
printf("---+");
printf("\n%2d|",row + 1);
for(col = 0; col< SIZE; col++)
printf(" %c |", board[row][col]); /* display counters in row*/
printf("\n");
}
printf(" +"); /*start the bottom line*/
for(col = 0; col<SIZE ; col++)
printf("---+"); /*display the bottom line*/
printf("\n"); /* end bottom line*/
}