From f45c80eb175b2a9ce859779629f6fd46ee58049a Mon Sep 17 00:00:00 2001 From: Abigail Date: Wed, 27 Jan 2021 17:21:44 +0100 Subject: Make C solution more like the other solutions. --- challenge-097/abigail/c/ch-2.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/challenge-097/abigail/c/ch-2.c b/challenge-097/abigail/c/ch-2.c index dd1441f6a4..47a0a65a61 100644 --- a/challenge-097/abigail/c/ch-2.c +++ b/challenge-097/abigail/c/ch-2.c @@ -32,13 +32,14 @@ int main (int argc, char ** argv) { } while ((strlen = getline (&line, &len, stdin)) != -1) { - strlen --; /* We don't care about the newline */ - int len = strlen / sections; /* Section length */ + strlen --; /* We don't care about the newline */ + int s_len = strlen / sections; /* Section length */ int sum = 0; - for (int i = 0; i < len; i ++) { + for (int i = 0; i < s_len; i ++) { int zeros = 0; for (int j = 0; j < sections; j ++) { - if (line [j * len + i] == '0') { + int index = j * s_len + i; + if (line [index] == '0') { zeros ++; } } -- cgit