aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan CHUNG <[email protected]>2024-03-26 13:51:59 +0800
committerAlan CHUNG <[email protected]>2024-03-26 13:51:59 +0800
commit9ce889b438622b40423068c0a9e8b98f4bb1ec39 (patch)
treea0f7063e691585caa08a23c61e9f70308900d111
parent74a6e60e17d8e71f9df37e3ac6ae30b4718e6034 (diff)
downloadziglings-9ce889b438622b40423068c0a9e8b98f4bb1ec39.tar.xz
ziglings-9ce889b438622b40423068c0a9e8b98f4bb1ec39.zip
106_files.zig actual test
-rw-r--r--build.zig2
-rw-r--r--exercises/106_files.zig10
2 files changed, 6 insertions, 6 deletions
diff --git a/build.zig b/build.zig
index 6c5a073..4517ff6 100644
--- a/build.zig
+++ b/build.zig
@@ -1123,7 +1123,7 @@ const exercises = [_]Exercise{
},
.{
.main_file = "106_files.zig",
- .output = "succefully wrote 18 bytes.",
+ .output = "Succefully wrote 18 bytes.",
},
.{
.main_file = "999_the_end.zig",
diff --git a/exercises/106_files.zig b/exercises/106_files.zig
index 0b593ed..b590679 100644
--- a/exercises/106_files.zig
+++ b/exercises/106_files.zig
@@ -35,8 +35,8 @@ pub fn main() !void {
// by doing nothing
//
// we want to catch error.PathAlreadyExists and do nothing
- error.PathAlreadyExists => {
- return;
+ ??? => {
+ ???;
},
// if is any other unexpected error we just propagate it through
else => return e,
@@ -46,7 +46,7 @@ pub fn main() !void {
// wait a minute
// opening a directory might fail!
// what should we do here?
- const output_dir: std.fs.Dir = try cwd.openDir("output", .{});
+ const output_dir: std.fs.Dir = cwd.openDir("output", .{});
// we try to open the file `zigling.txt`,
// and propagate the error up if there are any errors
@@ -56,11 +56,11 @@ pub fn main() !void {
// but here we are not yet done writing to the file
// if only there are a keyword in zig that
// allow you "defer" code execute to the end of scope...
- defer file.close();
+ file.close();
// !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("Succefully 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