107_files2.patch 1.2 KB

1234567891011121314151617181920212223242526
  1. --- exercises/107_files2.zig 2024-03-27 16:51:56.199719600 +0800
  2. +++ answers/107_files2.zig 2024-03-27 16:52:01.650935300 +0800
  3. @@ -33,7 +33,7 @@
  4. // initalize an array of u8 with all letter 'A'.
  5. // we need to pick a size of the array, 64 seems like a good number.
  6. // fix the initalization below
  7. - var content = ['A']*64;
  8. + var content = [_]u8{'A'} ** 64;
  9. // this should print out : `AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA`
  10. std.debug.print("{s}\n", .{content});
  11. @@ -41,12 +41,12 @@
  12. // can you go here to find a way to read the content ?
  13. // https://ziglang.org/documentation/master/std/#std.fs.File
  14. // hint: you might find two answer that are both vaild in this case
  15. - const byte_read = zig_read_the_file_or_i_will_fight_you(&content);
  16. + const byte_read = try file.read(&content);
  17. // Woah, too screamy, I know you're excited for zigling time but tone it down a bit
  18. // Can you print only what we read from the file ?
  19. std.debug.print("Successfully Read {d} byte: {s}\n", .{
  20. byte_read,
  21. - content, // change this line only
  22. + content[0..byte_read], // change this line only
  23. });
  24. }