From d6bf929fc82feb769d9e3b673fc7325a9bf99131 Mon Sep 17 00:00:00 2001 From: Mia Herkt Date: Thu, 2 Dec 2021 17:21:50 +0100 Subject: [PATCH] Day 2: Slightly simplify C solutions Not sure why I did it that way. Maybe because I was originally going to use strtol or something? --- 02/solution_1.c | 9 ++------- 02/solution_2.c | 9 ++------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/02/solution_1.c b/02/solution_1.c index f50634c..e8078c9 100644 --- a/02/solution_1.c +++ b/02/solution_1.c @@ -1,18 +1,13 @@ #include #include -#include int main(void) { FILE *fp = fopen("input.txt", "r"); - char buf[16] = {0}, *np; + char buf[16] = {0}; unsigned n, h = 0, v = 0; while (fgets(buf, 16, fp) != NULL) { - np = strchr(buf, ' '); - assert(np != NULL); - np++; - - sscanf(np, "%u", &n); + sscanf(buf, "%*s %u", &n); switch (buf[0]) { case 'd': diff --git a/02/solution_2.c b/02/solution_2.c index 5c3599b..6847386 100644 --- a/02/solution_2.c +++ b/02/solution_2.c @@ -1,18 +1,13 @@ #include #include -#include int main(void) { FILE *fp = fopen("input.txt", "r"); - char buf[16] = {0}, *np; + char buf[16] = {0}; unsigned n, aim = 0, h = 0, v = 0; while (fgets(buf, 16, fp) != NULL) { - np = strchr(buf, ' '); - assert(np != NULL); - np++; - - sscanf(np, "%u", &n); + sscanf(buf, "%*s %u", &n); switch (buf[0]) { case 'd':