From dea9ea660e0bd494aa0389ba3c31b269fa6eb8c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Kl=C3=A9ger?= Date: Tue, 7 Oct 2025 11:15:26 +0200 Subject: [PATCH] ex-03: Comment code --- exercise-03-rgb/main.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/exercise-03-rgb/main.c b/exercise-03-rgb/main.c index 47cd4bf..b2b88a0 100644 --- a/exercise-03-rgb/main.c +++ b/exercise-03-rgb/main.c @@ -40,6 +40,7 @@ int main() { return EXIT_FAILURE; } + // Strip out any whitespaces char* dst = input; for(char * src = input; *src; src++) { if(!isspace(*src)) { @@ -49,6 +50,10 @@ int main() { *dst = '\0'; int trimmed_len = strlen(input); + + // Check whether the provided input + // starts with rgb( + // and ends with ) if(strncmp(input, "rgb(", 4) != 0 || input[trimmed_len - 1] != ')') { debug("%s not in rgb(xxx) format", input); return invalid_input(); @@ -60,10 +65,13 @@ int main() { char* token = strtok(slice, ","); for(int i = 0; i < 3; i++) { + // strtok reached end prematurely if(token == NULL) { debug("Too few numbers"); return invalid_input(); } + + // Not a number if(!is_numeric(token)) { debug("%s is not a number", token); return invalid_input();