From 1d466f970c374ef45b2414725b5fdbc1a7f13e90 Mon Sep 17 00:00:00 2001 From: Andrew Scott Date: Mon, 2 Dec 2024 19:47:21 -0500 Subject: [PATCH] 2024: Add util.zig --- 2024/util.zig | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 2024/util.zig diff --git a/2024/util.zig b/2024/util.zig new file mode 100644 index 0000000..d67c2f8 --- /dev/null +++ b/2024/util.zig @@ -0,0 +1,11 @@ +const std = @import("std"); +const print = std.debug.print; + +pub fn readAllInput(day: u8, allocator: std.mem.Allocator) ![]const u8 { + var fileName: [16]u8 = undefined; + const inputFile = try std.fmt.bufPrint(&fileName, "day{d}.txt", .{day}); + const file = try std.fs.cwd().openFile(inputFile, .{}); + defer file.close(); + const stat = try file.stat(); + return try file.reader().readAllAlloc(allocator, stat.size); +}