RosettaCodeData/Task/Read-entire-file/Zig/read-entire-file-1.zig
2025-02-27 18:35:13 -05:00

16 lines
518 B
Zig

const std = @import("std");
pub fn main() !void {
var gpa: std.heap.GeneralPurposeAllocator(.{}) = .{};
defer _ = gpa.deinit();
const allocator = gpa.allocator();
var file = try std.fs.cwd().openFile("input_file.txt", .{});
defer file.close();
const file_content = try file.readToEndAlloc(allocator, (try file.stat()).size);
defer allocator.free(file_content);
std.debug.print("Read {d} octets. File content:\n", .{file_content.len});
std.debug.print("{s}", .{file_content});
}