#Is there a working example on how to get CL arguments?
1 messages · Page 1 of 1 (latest)
on 0.16+
pub fn main(init: std.process.Init) !void {
var args_iterator = try init.minimal.args.iterateAllocator(init.gpa);
defer args_iterator.deinit();
var i: usize = 0;
while (args_iter.next()) |arg| {
std.debug.print("arg {d}: \"{s}\"\n", .{ i, arg });
i += 1;
}
}
awesome, this works. someone should update the example ...
if you're talking about zig.guide, it seems to lag behind breaking changes
yeah, that
the best reference for the language is really just the stdlib docs. things get changed quite a bit still right now so anything older than a few months is probably outdated
okay
so is there a way now to find the amount of args before iterating over them?
you could either do two passes, counting on the first pass, or use args.toSlice(init.arena.allocator()), and take the .len of that slice