summaryrefslogtreecommitdiff
path: root/2022/day08/main.c
diff options
context:
space:
mode:
authorOrangerot <purple@orangerot.dev>2022-12-17 01:16:18 +0100
committerOrangerot <purple@orangerot.dev>2022-12-17 01:16:18 +0100
commit6596b48113ced669b206d2e1f1e8ba6edcba88a2 (patch)
tree02c7d01783390862d989df6c91aff968e03dd415 /2022/day08/main.c
adv2022 first 8 days
Diffstat (limited to '2022/day08/main.c')
-rw-r--r--2022/day08/main.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/2022/day08/main.c b/2022/day08/main.c
new file mode 100644
index 0000000..f80b1d0
--- /dev/null
+++ b/2022/day08/main.c
@@ -0,0 +1,36 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+int main(int argc, char *argv[] )
+{
+ FILE *file = fopen(argv[1], "r");
+ size_t size;
+
+ fseek(file, 0, SEEK_END); // seek to end of file
+ size = ftell(file); // get current file pointer
+ fseek(file, 0, SEEK_SET); // seek back to beginning of file
+
+ char *line = NULL;
+ size_t len;
+ ssize_t nlen;
+ char *forrest, *pf;
+
+ while ((nlen = getline(&line, &len, file)) != -1)
+ {
+ if (forrest == 0)
+ {
+ forrest = pf = malloc( (size / nlen) * sizeof(char*) );
+ int i=0;
+ for (; *pf != 0; pf++)
+ {
+ i++;
+ }
+ printf("%d, %zu, %zd", i, size, nlen);
+ }
+
+ }
+
+
+}
+