From 1023918c1cd9e44db076bf29f772fe2de28cdf87 Mon Sep 17 00:00:00 2001 From: fwcd Date: Wed, 10 Jan 2024 01:59:16 +0000 Subject: [PATCH] Read file line-by-line --- day16/src/day16.zig | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/day16/src/day16.zig b/day16/src/day16.zig index 933ff9b..3c44ac3 100644 --- a/day16/src/day16.zig +++ b/day16/src/day16.zig @@ -1,5 +1,26 @@ const std = @import("std"); -pub fn main() !void { - std.debug.print("Hello, World!\n", .{}); +const allocator = std.heap.page_allocator; +const stdout = std.io.getStdOut().writer(); + +pub fn main() !u8 { + var args = try std.process.argsAlloc(allocator); + if (args.len <= 1) { + try stdout.print("Usage: {s} \n", .{args[0]}); + return 1; + } + + var buf: [1024]u8 = undefined; + var file = try std.fs.cwd().openFile(args[1], .{}); + var bufReader = std.io.bufferedReader(file.reader()); + var reader = bufReader.reader(); + defer file.close(); + + while (try reader.readUntilDelimiterOrEof(&buf, '\n')) |line| { + try stdout.print("{s}\n", .{line}); + } + + try stdout.print("Part 1: {d}\n", .{0}); + + return 0; }