Skip to content

Instantly share code, notes, and snippets.

@utzig
Created October 6, 2018 12:41
Show Gist options
  • Select an option

  • Save utzig/1893da2a52670f4bcc7bff79b8682ff6 to your computer and use it in GitHub Desktop.

Select an option

Save utzig/1893da2a52670f4bcc7bff79b8682ff6 to your computer and use it in GitHub Desktop.
zig argv
const std = @import("std");
const warn = std.debug.warn;
const allocator = std.debug.global_allocator;

pub fn main() !void {
    const args = try std.os.argsAlloc(allocator);
    defer std.os.argsFree(allocator, args);

    warn("total args: {}\n", args.len);

    for (args) |arg, n| {
        warn("arg{}: {}\n", n, arg);
    }
}

output

$ zig build-exe argv.zig
$ ./argv 1 2 abc 4 5 def 
total args: 7
arg0: ./main
arg1: 1
arg2: 2
arg3: abc
arg4: 4
arg5: 5
arg6: def
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment