Skip to content

Instantly share code, notes, and snippets.

@cablehead
Created April 17, 2021 20:49
Show Gist options
  • Save cablehead/1bbdb064ee06adf20f69541f025e1fe1 to your computer and use it in GitHub Desktop.
Save cablehead/1bbdb064ee06adf20f69541f025e1fe1 to your computer and use it in GitHub Desktop.
std io with zig
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