diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2023-12-25 17:56:34 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2023-12-25 17:56:34 +0100 |
| commit | 94d0033ed89bb5bfb6500051296892fb7cea6c29 (patch) | |
| tree | 245eac2218310c958c2df2fad5109ea4f7b2a9d9 /2023/03/3b.c | |
| parent | 6a480c4eb9c96c82a8fd3663f0fbee4d32e56f19 (diff) | |
| download | aoc-94d0033ed89bb5bfb6500051296892fb7cea6c29.tar.gz aoc-94d0033ed89bb5bfb6500051296892fb7cea6c29.zip | |
Small cleanup
Diffstat (limited to '2023/03/3b.c')
| -rw-r--r-- | 2023/03/3b.c | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/2023/03/3b.c b/2023/03/3b.c index 27b5b7c..9bf4c27 100644 --- a/2023/03/3b.c +++ b/2023/03/3b.c | |||
| @@ -1,22 +1,16 @@ | |||
| 1 | #include <stdbool.h> | ||
| 2 | #include <stdio.h> | 1 | #include <stdio.h> |
| 3 | #include <stdlib.h> | 2 | #include <stdlib.h> |
| 4 | #include <string.h> | 3 | #include <string.h> |
| 5 | 4 | ||
| 6 | #define N 1000 | 5 | #define N 1000 |
| 7 | 6 | #define ISNUM(c) (c >= '0' && c <= '9') | |
| 8 | bool isnum(char c) { return c >= '0' && c <= '9'; } | ||
| 9 | 7 | ||
| 10 | int grab(char *buf) { | 8 | int grab(char *buf) { |
| 11 | int x; | 9 | if (!ISNUM(*buf)) return 0; |
| 12 | 10 | while (ISNUM(*buf)) buf--; | |
| 13 | if (!isnum(*buf)) | ||
| 14 | return 0; | ||
| 15 | |||
| 16 | while (isnum(*buf)) buf--; | ||
| 17 | buf++; | 11 | buf++; |
| 18 | x = atoi(buf); | 12 | int x = atoi(buf); |
| 19 | while (isnum(*buf)) *buf++ = '.'; | 13 | while (ISNUM(*buf)) *buf++ = '.'; |
| 20 | 14 | ||
| 21 | return x; | 15 | return x; |
| 22 | } | 16 | } |
