diff options
author | Alan CHUNG <deeralan827@gmail.com> | 2024-03-27 16:40:24 +0800 |
---|---|---|
committer | Alan CHUNG <deeralan827@gmail.com> | 2024-03-27 16:40:24 +0800 |
commit | 223fc79e441dab99297472a0cfe8a4c63e423b4e (patch) | |
tree | 91edb6b111fb1a8dc155abdc73a1e56079f76e85 /exercises/106_files.zig | |
parent | 69bc9a072349b5e712b709c238daceec211d6687 (diff) |
106 & 107
Diffstat (limited to 'exercises/106_files.zig')
-rw-r--r-- | exercises/106_files.zig | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/exercises/106_files.zig b/exercises/106_files.zig index b590679..78e6611 100644 --- a/exercises/106_files.zig +++ b/exercises/106_files.zig @@ -35,9 +35,7 @@ pub fn main() !void { // by doing nothing // // we want to catch error.PathAlreadyExists and do nothing - ??? => { - ???; - }, + ??? => {}, // if is any other unexpected error we just propagate it through else => return e, }; @@ -46,7 +44,8 @@ pub fn main() !void { // wait a minute // opening a directory might fail! // what should we do here? - const output_dir: std.fs.Dir = cwd.openDir("output", .{}); + var output_dir: std.fs.Dir = cwd.openDir("output", .{}); + defer output_dir.close(); // we try to open the file `zigling.txt`, // and propagate the error up if there are any errors @@ -60,7 +59,7 @@ pub fn main() !void { // !you are not allow to switch this two lines to before file closing line! const byte_written = try file.write("It's zigling time!"); - std.debug.print("Succefully wrote {} bytes.\n", .{byte_written}); + std.debug.print("Successfully wrote {} bytes.\n", .{byte_written}); } // to check if you actually write to the file, you can either, // 1. open the file on your text editor, or |