Data update
This commit is contained in:
parent
8e4e15fa56
commit
72eb4943cb
1853 changed files with 35514 additions and 9441 deletions
2
Task/Read-entire-file/Forth/read-entire-file-2.fth
Normal file
2
Task/Read-entire-file/Forth/read-entire-file-2.fth
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
: read-file "foo.txt" GET-FILE TYPE ;
|
||||
read-file
|
||||
|
|
@ -1 +1,2 @@
|
|||
(require racket/file)
|
||||
(file->string "foo.txt")
|
||||
|
|
|
|||
|
|
@ -1,18 +1,14 @@
|
|||
const std = @import("std");
|
||||
|
||||
const File = std.fs.File;
|
||||
|
||||
pub fn main() (error{OutOfMemory} || File.OpenError || File.ReadError)!void {
|
||||
pub fn main() !void {
|
||||
var gpa: std.heap.GeneralPurposeAllocator(.{}) = .{};
|
||||
defer _ = gpa.deinit();
|
||||
const allocator = gpa.allocator();
|
||||
|
||||
const cwd = std.fs.cwd();
|
||||
|
||||
var file = try cwd.openFile("input_file.txt", .{ .mode = .read_only });
|
||||
var file = try std.fs.cwd().openFile("input_file.txt", .{});
|
||||
defer file.close();
|
||||
|
||||
const file_content = try file.readToEndAlloc(allocator, comptime std.math.maxInt(usize));
|
||||
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});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue