From f4735ab54fd2e86f9b9a517011a8a5c3948c4fdd Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Sun, 3 Dec 2023 18:31:34 +0400 Subject: [PATCH] Pass just a line to parse_number(). --- day3/p2.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/day3/p2.c b/day3/p2.c index 1795cd1..753be5c 100644 --- a/day3/p2.c +++ b/day3/p2.c @@ -6,7 +6,7 @@ #include #include -int32_t parse_number(char **engine, ssize_t i, ssize_t j); +int32_t parse_number(char *line, ssize_t j); int main(int argc, char **argv) { FILE *input; @@ -49,38 +49,38 @@ int main(int argc, char **argv) { int8_t p = 0; if (isdigit(engine[i][j+1])) { - n *= parse_number(engine, i, j+1); + n *= parse_number(engine[i], j+1); p++; } if (isdigit(engine[i][j-1])) { - n *= parse_number(engine, i, j-1); + n *= parse_number(engine[i], j-1); p++; } if (isdigit(engine[i+1][j])) { - n *= parse_number(engine, i+1, j); + n *= parse_number(engine[i+1], j); p++; } else { if (isdigit(engine[i+1][j+1])) { - n *= parse_number(engine, i+1, j+1); + n *= parse_number(engine[i+1], j+1); p++; } if (isdigit(engine[i+1][j-1])) { - n *= parse_number(engine, i+1, j-1); + n *= parse_number(engine[i+1], j-1); p++; } } if (isdigit(engine[i-1][j])) { - n *= parse_number(engine, i-1, j); + n *= parse_number(engine[i-1], j); p++; } else { if (isdigit(engine[i-1][j+1])) { - n *= parse_number(engine, i-1, j+1); + n *= parse_number(engine[i-1], j+1); p++; } if (isdigit(engine[i-1][j-1])) { - n *= parse_number(engine, i-1, j-1); + n *= parse_number(engine[i-1], j-1); p++; } } @@ -99,14 +99,14 @@ int main(int argc, char **argv) { return 0; } -int32_t parse_number(char **engine, ssize_t i, ssize_t j) { +int32_t parse_number(char *line, ssize_t j) { int32_t n = 0; int32_t multiplier = 1; - while (isdigit(engine[i][j+1])) j++; + while (isdigit(line[j+1])) j++; - while (isdigit(engine[i][j])) { - n += (engine[i][j]&0xf) * multiplier; + while (isdigit(line[j])) { + n += (line[j]&0xf) * multiplier; multiplier *= 10; j--; }