Article View: comp.sys.amiga.tech
Article #4675Re: I/O of complex data structures in C
From: Staff OACIS
Date: Fri, 03 Aug 1990 17:07
Date: Fri, 03 Aug 1990 17:07
33 lines
2228 bytes
2228 bytes
In article <140087@sun.Eng.Sun.COM> jasonf@cetemp.Eng.Sun.COM (Jason Freund) writes:
> 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.
>
When you call fwrite, it treats the memory pointed to (in this case, your
structure) as a contiguous block of memory of the specified size. It makes
no attempt to interpret the elements of the structure. If the structure contains
only data, then this is not a problem. If, however, it contains pointers, then
you have a problem because the items pointed to will not be in the same location
when you read the data back in.
> Could someone explain in some detail what the arguments mean? Or point
>me to a source that could?
>
pointer = the address of the data block to write out to the file
sizeof(*pointer) = the size of what the pointer points to, in other words the
size of the data block being written
items = the number of blocks of that size contained in the buffer
stream = the file handle for the open file to write to.
In other words, the routine writes (items * sizeof(*pointer)) bytes to file
"stream" from the buffer pointed to by "pointer".
--
John Meissen .............................. Oregon Advanced Computing Institute
jmeissen@oacis.org (Internet) | "That's the remarkable thing about life;
..!sequent!oacis!jmeissen (UUCP) | things are never so bad that they can't
jmeissen (BIX) | get worse." - Calvin & Hobbes
Technical Details
Message-ID:
<581@oregon.oacis.org>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!yale!mintaka!ogicse!oregon!jmeissenReferences:
<140087@sun.Eng.Sun.COM>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!yale!mintaka!ogicse!oregon!jmeissen From: jmeissen@oregon.oacis.org ( Staff OACIS) Newsgroups: comp.sys.amiga.tech Subject: Re: I/O of complex data structures in C Message-ID: <581@oregon.oacis.org> Date: 3 Aug 90 17:07:01 GMT References: <140087@sun.Eng.Sun.COM> Organization: Oregon Advanced Computing Institute (OACIS), Beaverton, OR Lines: 33