Mail Archives: djgpp/1997/08/19/10:41:55
>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, <bokovoy AT bspu DOT ac DOT by>
---== The Soft Age coming soon ==---
- Raw text -