107_files2.patch 1.2 KB

1234567891011121314151617181920212223242526
  1. --- exercises/107_files2.zig 2025-03-13 15:26:59.532367792 +0200
  2. +++ answers/107_files2.zig 2025-03-14 22:08:35.167953736 +0200
  3. @@ -33,7 +33,7 @@
  4. // initalize an array of u8 with all letter 'A'
  5. // we need to pick the 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 answers that are both valid in this case
  15. - const bytes_read = zig_read_the_file_or_i_will_fight_you(&content);
  16. + const bytes_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} bytes: {s}\n", .{
  20. bytes_read,
  21. - content, // change this line only
  22. + content[0..bytes_read], // change this line only
  23. });
  24. }