Created
November 6, 2019 20:37
-
-
Save mikdusan/9a99082dced5f014f390e22e3d134d7c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
pub fn main() !void { | |
var arena_object = std.heap.ArenaAllocator.init(std.heap.direct_allocator); | |
defer arena_object.deinit(); | |
const arena = &arena_object.allocator; | |
std.debug.warn("Please enter a new title to add in the library:\n"); | |
var buf = try std.Buffer.initSize(arena, 0); | |
const title = try std.io.readLine(&buf); | |
if (title.len >= 3) { | |
std.debug.warn("'{}' has been successfully added to the library.\n", title); | |
} else { | |
std.debug.warn("That title is too short.\n"); | |
} | |
try buf.appendByte('\n'); | |
const file = try std.fs.File.openWrite("books.txt"); | |
defer file.close(); | |
try file.write(buf.toSliceConst()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
added comments