Date: Tue, 19 Aug 1997 16:52:32 -0200 Message-Id: <199708191852.QAA005.81@ns1.bspu.ac.by> To: From: Alexander Bokovoy Cc: DJGPP mailing list Subject: Re: Writing a struct to disk MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk >Under djgpp, what is the best way to write a bunch of structs to a >file? For instance, I'd like to write a linked list to a file node by >node, then be able to read the nodes back and reconstruct the list. A >node could be something like the following: > >struct node { > int number; > unsigned char age; > char *name; > node *next; >} > >The ints and chars would be relatively easy, but I don't see how a >variable length string could be written. Of course, the node pointer >wouldn't be written. > You can use the technique which used in PASCAL: TO WRITE: 1. write [length] of string (include last zero character) as int16 (in many cases int16 enough) 2. write string as a array of unsigned char TO READ: 1. read [length] of string as int16 2. get [length] unsigned chars from heap 3. read into this memory block [length] chars from file. -- Alexander Bokovoy, ---== The Soft Age coming soon ==---