I/O of complex data structures in C

Jason Freund jasonf at cetemp.Eng.Sun.COM
Fri Aug 3 10:02:52 AEST 1990



-- somewhat hypothetical situation representing a real problem --

	Ok.  Suppose I am writing a game in ansi C that saves a bunch of 
different maze levels as separate files.  The player walks around, changes
some things, and then leaves.  When the game starts, I want to load level 1.
Everytime he changes levels, I load up the new level and save the old one.

	Basically, a maze is a complex data structure (a 2D array of and array
of pointers to blah, blah... (it's deep)).  So that means I want to use fread()
and fwrite() (right?)  My programming book says *very* little on those
commands, but what they do say leads me to believe that those are the commands
I want.  

	When you save data in a database, does the program just go:
"fwrite(pointer, sizeof, *pointer, items, stream)" which somehow magically
saves every piece of data (specified in the arguments) in such a way that it
will be able to read in every piece of data back into their correct cells in
the data structure?  That is what I want to do -- and I want to know if fread
and fwrite can do it.

	Could someone explain in some detail what the arguments mean? Or point
me to a source that could?

Thanks,

Jason Freund, Sun Microsystems,  jasonf at cetemp.Corp.sun.com  <== summer address
Deprtmnt of Computer Science, Univ California, Davis. freund at sakura.ucdavis.edu
Quantum Link: JasonF5,  Compu$erve: 72007,244, 690 Erie Dr, Sunnyvale, CA 94087
-------------------------------------------------------------------------------
STOLEN QUOTES -- Please give the authors credit if you know who they are!    
"To understand recursion, you need to understand recursion."
"Wow!  Virtual memory!  Now I'm gonna build me a REALLY big ram disk!"
"My other computer is a SUN3/50."  "E. Pluribus UNIX"   -- authors unkown 



More information about the Comp.lang.c mailing list