What is the golang equivalent of the following C code ?
fwrite(&E, sizeof(struct emp), n, f);
I tried using
[]byte(i)
to convert it, but that won't work, it seems.
You should not do that, just use a serialization format that supports automatic serialization and deserialization. Go's standard library supports:
Gob: go binary encoding of structs. Recommended when you're not interested in interchange with other languages. https://golang.org/pkg/encoding/gob/
JSON: Welp, you know... If you need to exchange serialized data with other languages. https://golang.org/pkg/encoding/json/
XML: If you're feeling retro.
And of course protobuf is another option to consider, if you want type safe interchange with other languages, which json doesn't support. https://github.com/golang/protobuf