I’m trying to simply read a command line argument. What sounds simple doesn’t seem to be so in reality while trying.
const std = @import("std");
pub fn main() void {
var args = try std.process.argsWithAllocator();
defer args.deinit();
_ = args.skip();
std.debug.print(args.next());
std.debug.print("12th fibonacci number is {d}", .{fibonacci(12)});
}
I’m getting this error when I’m doing zig run. Have read other discussions and googled enough about this, but no luck. Can someone hint me in the right direction please? I’m on Windows.
I think there is some special syntax for passing arguments ? I don’t remember but when I do zig build run I have to do zig build run – argument. So maybe you also need a double dash like this ?
Here’s a big clue that helped me, zig run, zig test, and others work on individual files (I think mostly) and you can get help with zig run --help.
zig build run and zig build test are NOT the same thing. zig build compiles and runs build.zig and run and test are part of that build program. If you look in build.zig you will see the test and run steps defined (and they can be defined however you want: zig build test could rm -rf / for all it cares.
For zig run main.zig you need the double slashes so it knows the arguments are to main.zig and not zig run. If you did a build and ran it main 12 would work fine.