Browse Source

refactoring: implemented validate input

remotes/origin/ticTacToe
Aimee Reincke 2 years ago
parent
commit
050adc24c1
  1. 16
      src/c/ticTacToe.c

16
src/c/ticTacToe.c

@ -32,11 +32,17 @@ void initField(char field[3][3]) {
void getPlayerInput(char field[3][3]){ void getPlayerInput(char field[3][3]){
int row, col; int row, col;
printf("Enter the field as row col: ");
scanf("%d %d", &row, &col);
row -= 1;
col -= 1;
field[row][col] = 'O';
bool valid = false;
while (!valid){
printf("Enter the field as row col: ");
scanf("%d %d", &row, &col);
row -= 1;
col -= 1;
if(validateUserInput(row, col)){
field[row][col] = 'O';
valid = validateUserInput(row, col);
}
}
} }
bool validateUserInput(int row, int col){ bool validateUserInput(int row, int col){

Loading…
Cancel
Save