From 764252dace8cf0fe1b4dfb71375d920124cb1baf Mon Sep 17 00:00:00 2001 From: Aimee Reincke Date: Mon, 30 Jan 2023 11:18:09 +0100 Subject: [PATCH] improved print and init field function --- src/c/ticTacToe.c | 22 +++++++++++++--------- src/c/ticTacToe.h | 3 ++- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/c/ticTacToe.c b/src/c/ticTacToe.c index b575e77..c2347cb 100644 --- a/src/c/ticTacToe.c +++ b/src/c/ticTacToe.c @@ -16,7 +16,7 @@ void printPrompt(){ void printField(char field[3][3]){ for (int i = 0; i < 3; i++){ for (int j = 0; j < 3; j++){ - printf("%d", field[i][j]); + printf("%c", field[i][j]); if (j < 2) { printf("|"); } @@ -25,13 +25,17 @@ void printField(char field[3][3]){ } } -char initField(){ - char field[3][3] = - { - {'-','-','-'}, - {'-','-','-'}, - {'-','-','-'} - }; - return field; +void initField(char field[3][3]) { + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + field[i][j] = '-'; + } + } } +void getPlayerInput(char field[3][3]){ + int row, col; + printf("Enter the field as row col: "); + scanf("%d %d", &row, &col); + field[row][col] = 'O'; +} \ No newline at end of file diff --git a/src/c/ticTacToe.h b/src/c/ticTacToe.h index 350fc78..832972c 100644 --- a/src/c/ticTacToe.h +++ b/src/c/ticTacToe.h @@ -4,6 +4,7 @@ int something(int a); void printPrompt(); void printField(char field[3][3]); -char initField(); +void initField(char field[3][3]); +void getPlayerInput(char field[3][3]); #endif \ No newline at end of file