Re: Writing To Binary File
- Posted by DerekParnell (admin) Mar 09, 2009
- 943 views
OK, I'm getting a little bit more of it, but my code still returns an error whenever I try to run it. It dosen't function correctley. Here's what I'm trying to do.
integer fn fn = open("sav.frst","wb") if fn = -1 then then puts(1,"Cannot write file!\n") else wPrint(fn,HP) end if
However when whenver I do that, my program crashes with a console window comes up and has a bunch of errors in it, also I'm using the win32lib, so I am wondering what I am doing wrong
I assume you are not strictly needing a binary file, but just one in which you can write and read arbitary Euphoria objects. In which case, use the 'print' routine.
integer fn fn = open("sav.frst","wb") if fn = -1 then then puts(1,"Cannot write file!\n") else print(fn,HP) end if
This actually writes the data out as human-readable text rather than in strict binary format, but if that isn't an issue you should be fine. Use the get() function to read the data back in.
If you really need a pure binary format, then you might need to roll-your-own or use the EDS library. There will be a binary form of print()/get() available in the v4.0 release.