3 ms·
They have several examples of reading a file etc, e.g.: var file = os.File.openRead(arg) catch |err| { warn("Unable to open file: {}\n", @e
by coldtea 8y ago
They have several examples of reading a file etc, e.g.:
var file = os.File.openRead(arg) catch |err| {
warn("Unable to open file: {}\n", @errorName(err));
return err;
};
defer file.close();
The rest should be basically string operations...
- new4thaccount 8y agoI'm not sure how I missed this, but thank you for bringing it to my attention. It seems straightforward enough. I should be able to figure out the string operations.
- jstimpfle 8y agoIt's also very straightforward to just link to libc and use fopen()/fread()/fwrite()/fclose()/fflush(). That's how I do it with my own (much less mature) language.
- abhijat 8y agoCould you be so kind as to point out where you found this example please? I could not find it in the documentation link in parent post.
- coldtea 8y agoI/O examples such as that already exist on the Zig webpage, e.g. here: https://ziglang.org/#A-fresh-take-on-error-handling https://ziglang.org/#A-fresh-take-on-error-handling But the one I posted is from GitHub, where it has e.g: https://github.com/ziglang/zig/blob/8139c5a516eaa217ed76acdf09496895451c5c5c/example/cat/main.zig https://github.com/ziglang/zig/blob/8139c5a516eaa217ed76acdf... also: https://github.com/ziglang/zig/blob/92d9cef07116da8639ac33b7fd83ba1b35f0750c/std/io/test.zig https://github.com/ziglang/zig/blob/92d9cef07116da8639ac33b7...
- new4thaccount 8y agoThanks! It would be good to get this as part of the official doc. I can follow along with almost any language if there is enough examples I can piece together. I didn't think about scrolling through a bunch of GitHub pages. It isn't as convenient, but probably a better example of how to put together a full program as well as style.
- coldtea 8y agoYeah, Zig needs a "Zig by example" (akin to the Go and Rust by example pages).