From d93f1bf66b33c8d7433f519c825f84e78ff792fd Mon Sep 17 00:00:00 2001 From: Eric Chou Date: Wed, 12 Mar 2025 20:37:02 +0800 Subject: [PATCH] Reject multiple column letters in get_input This update adds validation to reject inputs with multiple column letters, such as "aa", which were previously treated as out of bounds instead of being explicitly rejected. Additionally, a comment was updated for clarity, changing "row number" to "row numbers" for consistency. Co-authored-by: charliechiou --- main.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index 9c5ec3a..7508167 100644 --- a/main.c +++ b/main.c @@ -59,6 +59,14 @@ static int get_input(char player) parseX = 1; for (int i = 0; i < (r - 1); i++) { if (isalpha(line[i]) && parseX) { + // input has multiple column alphabets + if (i > 0 && isalpha(line[i])) { + printf( + "Invalid operation: multiple column alphabets " + "detected\n"); + x = y = 0; + break; + } x = x * 26 + (tolower(line[i]) - 'a' + 1); if (x > BOARD_SIZE) { // could be any value in [BOARD_SIZE + 1, INT_MAX] @@ -92,7 +100,7 @@ static int get_input(char player) x = y = 0; break; } - // input does not have row number + // input does not have row numbers if (x > 0 && x <= BOARD_SIZE && parseX == 1) printf("Invalid operation: No row number\n"); x -= 1;