Created
April 17, 2021 20:49
-
-
Save cablehead/1bbdb064ee06adf20f69541f025e1fe1 to your computer and use it in GitHub Desktop.
std io with zig
This file contains hidden or 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 { | |
const stdout = std.io.getStdOut().writer(); | |
const stdin = std.io.getStdIn().reader(); | |
const a = std.testing.allocator; | |
var buf = std.ArrayList(u8).init(a); | |
defer buf.deinit(); | |
var args = std.process.args(); | |
_ = args.skip(); | |
var prefix = try args.next(a) orelse { | |
std.debug.warn("prefix required.\n", .{}); | |
return; | |
}; | |
while (true) { | |
stdin.readUntilDelimiterArrayList(&buf, '\n', 1024) catch return; | |
try stdout.print("{s}: {s}\n", .{ prefix, buf.items }); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment