PDA

View Full Version : write parameters into file


alaios
07-09-2005, 10:42 AM
Hi... I have some variables in c code and i want to write them in to a file in such way so i can read them back and put them in the variables i have written them... any suggestions?
Thx alot

suryad
07-09-2005, 11:40 AM
Well that would require a lot of string processing...I can think of a few ways in Java...using PROPERTIES files...but hmm...not in C....but still thats an interesting question. any takers?

Serex
07-09-2005, 12:00 PM
I remember doing something similar for a game i wrote a while back. It was a good way to save/store information while the player wasnt 'playing'. if i get time to search through my source ill post it for you

aman
07-09-2005, 04:41 PM
The easiest way to do this is to store all your variables in a struct. When it comes time to write the data to file, it's as simple as one fwrite() call. When it comes time to retrieve the data from the file, it's as simple as one fread() call. read/write the whole struct to/from the file in one operation.

The next best way is to write your preferences line by line to a file, and read them back line by line, or build a simple text parser for reading

.

suryad
07-09-2005, 09:49 PM
Yeah...in Java you can serialize objects to a file...and then just pull out the object kinda like what aman said about using structs. I miss structs.