From 050adc24c1925008eddaf5277fdf015ca7427e6c Mon Sep 17 00:00:00 2001 From: Aimee Reincke Date: Mon, 30 Jan 2023 13:52:00 +0100 Subject: [PATCH] refactoring: implemented validate input --- src/c/ticTacToe.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/c/ticTacToe.c b/src/c/ticTacToe.c index f8d5e1a..38be611 100644 --- a/src/c/ticTacToe.c +++ b/src/c/ticTacToe.c @@ -32,11 +32,17 @@ void initField(char field[3][3]) { void getPlayerInput(char field[3][3]){ 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){