5 ms·
It looks like Zig has some decent documentation (something I treasure), but it looks like file I/O is missing. I'm sure it assumes the user is at least intermed
by new4thaccount 7y ago
It looks like Zig has some decent documentation (something I treasure), but it looks like file I/O is missing. I'm sure it assumes the user is at least intermediate with C (I can only get by with lots of googling). I'll give Zig a try if someone can put up an example of reading a .CSV file (something I do a lot and wish I had faster tools to do) and if it is less of a hassle than C/C++.
https://ziglang.org/documentation/master/ https://ziglang.org/documentation/master/
The install seems to also be a lot more straightforward than many of the other low level languages that I have tried.
- coldtea 7y agoThey 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 7y 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 7y 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 7y 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 7y 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 7y 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 7y agoYeah, Zig needs a "Zig by example" (akin to the Go and Rust by example pages).