106_files.patch 1.1 KB

1234567891011121314151617181920212223242526272829
  1. --- exercises/106_files.zig 2024-03-27 16:52:05.660910200 +0800
  2. +++ answers/106_files.zig 2024-03-27 16:52:09.649422200 +0800
  3. @@ -35,7 +35,7 @@
  4. // by doing nothing
  5. //
  6. // we want to catch error.PathAlreadyExists and do nothing
  7. - ??? => {},
  8. + error.PathAlreadyExists => {},
  9. // if is any other unexpected error we just propagate it through
  10. else => return e,
  11. };
  12. @@ -44,7 +44,7 @@
  13. // wait a minute
  14. // opening a directory might fail!
  15. // what should we do here?
  16. - var output_dir: std.fs.Dir = cwd.openDir("output", .{});
  17. + var output_dir: std.fs.Dir = try cwd.openDir("output", .{});
  18. defer output_dir.close();
  19. // we try to open the file `zigling.txt`,
  20. @@ -55,7 +55,7 @@
  21. // but here we are not yet done writing to the file
  22. // if only there are a keyword in zig that
  23. // allow you "defer" code execute to the end of scope...
  24. - file.close();
  25. + defer file.close();
  26. // !you are not allow to switch this two lines to before file closing line!
  27. const byte_written = try file.write("It's zigling time!");