From ec2928b40a4a5a0fa6f7b0205f3152071e112a3f Mon Sep 17 00:00:00 2001 From: Lucas Heil Date: Wed, 7 Feb 2024 17:19:02 +0100 Subject: [PATCH] Commit 24 code --- src/main/c/sudoku.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/main/c/sudoku.c b/src/main/c/sudoku.c index 77122dc..705e694 100644 --- a/src/main/c/sudoku.c +++ b/src/main/c/sudoku.c @@ -448,8 +448,35 @@ void tipFunction(int grid[SIZE][SIZE]) { void inputFunction(int grid[SIZE][SIZE]) { printf("\nInput function - Choose an action:\n"); + printf("1. Insert value in an empty field\n"); + printf("2. Clear an already filled field\n"); - + int action; + + while (true){ + char in_str[10]; + scanf("%s", in_str); + + action = in_str[0] - '0'; // Convert the first character to an integer + + if ((action >= 1 && action <= 2) && in_str[1] == '\0') { + break; + } else { + printf("Invalid input. Please enter a number between 1 and 2.\n"); + } + } + + switch (action) { + case 1: + printf("Case 1 \n"); + break; + + case 2: + printf("Case 2 \n"); + break; + default: + printf("Invalid input. Please enter 1 or 2.\n"); + } }