#how to check string
1 messages · Page 1 of 1 (latest)
argv returns a [*:0], which is a pointer that ends with the null terminator character 0. This is often used for strings in c. When you use asBytes on this type, it provides the bytes of the pointer. The bytes of the pointer pointing to the string are not equal to "run". Instead, you can use span as suggested by Jodi to convert the pointer into a slice, which then can be passed to the eql function.
the conversions of these types are deceptively tricky for beginners. Are there any good resources that can help grapple with this topic?
I searched zig pointers and this is a pretty good blog post. https://www.nmichaels.org/zig/pointers.html. Doing the "ziglings" can also help
if i dereferenced the pointer and then asBytes on the dereferneced pointer wouldnt that work?
if (std.mem.eql(u8, result, "run")) {
print("found arg run\n", .{});
}```
```src/main.zig:19:34: error: index syntax required for unknown-length pointer type '[*:0]u8'
const result = std.os.argv[1].*;```
You cant dereference a multi pointer
How would that work
The compiler would have no way to know how big the array its pointing to is