mirror of
https://codeberg.org/andyscott/advent-of-code.git
synced 2024-12-21 17:13:10 -05:00
2024: Add util.zig
This commit is contained in:
parent
9f03226d18
commit
1d466f970c
1 changed files with 11 additions and 0 deletions
11
2024/util.zig
Normal file
11
2024/util.zig
Normal file
|
@ -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);
|
||||
}
|
Loading…
Reference in a new issue