Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

PureGDK / saving and loading data

Author
Message
Hawkblood
7
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 29th Jun 2012 06:01
I used to use fopen() and fread()/fwrite() to save data formats. This method worked fine, but is there a better method to save/load complex data structures like custom structs?

The fastest code is the code never written.
WLGfx
9
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 29th Jun 2012 21:33
If you open a file using "r" or "w" you can change that to "rb" or "wb" for binary mode and then use something like fwrite( &mystruct, sizeof(mystruct), 1, file );

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
Hawkblood
7
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 3rd Jul 2012 04:17
Yea. That's what I have been doing. VS2008 says:
Quote: "warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details."

I mean, I know it's just a warning, but I want something that won't generate that and work just as good (if not better). Yes, there's fopen_s, but is there something better?

The fastest code is the code never written.
WLGfx
9
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 5th Jul 2012 06:17
I still mainly use the Ansi C stdio.h for most of my file handling but there's also the standard C++ <fstream> http://www.cplusplus.com/reference/iostream/fstream/ which is something I'll have to start using a lot more instead...

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
Hawkblood
7
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 6th Jul 2012 02:30
I have a new problem. I purchased the RC4 version and it's telling me the "trial version" is expired. I tried reinstalling it, but I still get the same problem.

The fastest code is the code never written.
Olby
13
Years of Service
User Offline
Joined: 21st Aug 2003
Location:
Posted: 6th Jul 2012 12:23
If you have purchased the commercial license then you must download and install the commercial edition. There should be two downloads one for the beta RC4 and one for the commercial RC4. Get the commercial one and copy the serial code. During the setup it will ask for the serial. Once registered your RC4 should not expire.


Intel Core2Duo 2.2GHZ, 2GB, GeForce 8600M GT 1280MB, Windows Vista Ultimate SP2, PureBasic 4.61 + DarkGDK 2.0
Hawkblood
7
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 10th Jul 2012 16:51 Edited at: 10th Jul 2012 16:54
Yea. It was the gdkengine.dll that was giving me that. I had to copy the commercial version to my program's directory.

Oh, by the way, WLGfx:

I have tried the fstream approach. It's a lot of trouble if you ask me. I can't get it to save structures or classes as data types. In fact, it seems to only take character strings.....?

The fastest code is the code never written.
WLGfx
9
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 11th Jul 2012 04:31
Yeah, I've been faffing about with streams myself over the last couple of days. In some cases they're useful but for files I still prefer stdio.h. I also still use printf() instead of cout << stuff...

Although mostly I still use fopen() instead of fopen_s() even though it's deprecated, writing out complete structures/classes is easy. You do need to make sure that you've opened the file as binary for both reading and writing.

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!

Login to post a reply

Server time is: 2017-07-22 03:53:03
Your offset time is: 2017-07-22 03:53:03