From 2b81df57cf6482ce1e2c718d5180e3fbe2f0df50 Mon Sep 17 00:00:00 2001 From: Eric Chou Date: Thu, 13 Mar 2025 00:50:54 +0800 Subject: [PATCH] Reject row number 0 as invalid input This update adds validation to reject row number 0, which was previously allowed. While row numbers exceeding BOARD_SIZE were already handled, there was no explicit check for 0. An error is now triggered when 0 is entered. Co-authored-by: charliechiou --- main.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/main.c b/main.c index 7508167..f269c62 100644 --- a/main.c +++ b/main.c @@ -85,6 +85,12 @@ static int get_input(char player) parseX = 0; if (isdigit(line[i])) { y = y * 10 + line[i] - '0'; + // index cannot be 0 + if (y == 0) { + printf("Invalid operation: index cannot be 0\n"); + x = y = 0; + break; + } if (y > BOARD_SIZE) { // could be any value in [BOARD_SIZE + 1, INT_MAX] y = BOARD_SIZE + 1;