106_files.patch 1.1 KB

1234567891011121314151617181920212223242526272829
  1. --- exercises/106_files.zig 2024-05-05 00:48:25.808548611 +0200
  2. +++ answers/106_files.zig 2024-05-05 01:00:40.742969819 +0200
  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 were a keyword in zig that
  23. // allows you "defer" code execute to the end of scope...
  24. - file.close();
  25. + defer file.close();
  26. // !you are not allowed to switch these two lines above the file closing line!
  27. const byte_written = try file.write("It's zigling time!");