From 1e552a1dd6dac663a9329e5c71c5c7c245f2ed1e Mon Sep 17 00:00:00 2001 From: Chris Boesch Date: Fri, 9 Jan 2026 22:56:23 +0100 Subject: I/O improvements --- exercises/026_hello2.zig | 8 ++++---- exercises/034_quiz4.zig | 4 ++-- exercises/106_files.zig | 6 ++++-- exercises/107_files2.zig | 5 +++-- 4 files changed, 13 insertions(+), 10 deletions(-) (limited to 'exercises') diff --git a/exercises/026_hello2.zig b/exercises/026_hello2.zig index 9cd8bbc..f110d87 100644 --- a/exercises/026_hello2.zig +++ b/exercises/026_hello2.zig @@ -5,9 +5,6 @@ // const std = @import("std"); -// Instance for input/output operations; we will learn more about this later. -const io = std.Options.debug_io; - // Take note that this main() definition now returns "!void" rather // than just "void". Since there's no specific error type, this means // that Zig will infer the error type. This is appropriate in the case @@ -17,7 +14,10 @@ const io = std.Options.debug_io; // You can find more information at: // https://ziglang.org/documentation/master/#Inferred-Error-Sets // -pub fn main() !void { +pub fn main(init: std.process.Init) !void { + // Instance for input/output operations; we will learn more about this later. + const io = init.io; + // We get a Writer for Standard Out... var stdout_writer = std.Io.File.stdout().writer(io, &.{}); // ...and extract its interface so we can print() to it. diff --git a/exercises/034_quiz4.zig b/exercises/034_quiz4.zig index 28f2291..b33a6f5 100644 --- a/exercises/034_quiz4.zig +++ b/exercises/034_quiz4.zig @@ -6,11 +6,11 @@ // my_num=42 // const std = @import("std"); -const io = std.Options.debug_io; const NumError = error{IllegalNumber}; -pub fn main() void { +pub fn main(init: std.process.Init) !void { + const io = init.io; var stdout_writer = std.Io.File.stdout().writer(io, &.{}); const stdout = &stdout_writer.interface; diff --git a/exercises/106_files.zig b/exercises/106_files.zig index b2ebb17..bf4de9b 100644 --- a/exercises/106_files.zig +++ b/exercises/106_files.zig @@ -24,9 +24,11 @@ // performance. We'll learn about buffered I/O in a later exercise. // const std = @import("std"); -const io = std.Options.debug_io; -pub fn main() !void { +pub fn main(init: std.process.Init) !void { + // default I/O implementation + const io = init.io; + // first we get the current working directory const cwd: std.Io.Dir = std.Io.Dir.cwd(); diff --git a/exercises/107_files2.zig b/exercises/107_files2.zig index a11c46a..c363086 100644 --- a/exercises/107_files2.zig +++ b/exercises/107_files2.zig @@ -21,9 +21,10 @@ // performance. We'll learn about buffered I/O in a later exercise. const std = @import("std"); -const io = std.Options.debug_io; -pub fn main() !void { +pub fn main(init: std.process.Init) !void { + const io = init.io; + // Get the current working directory const cwd = std.Io.Dir.cwd(); -- cgit v1.2.3