Hi,
I have a quick general question. For reading and writing in binary mode, I have learned that there are functions such as fread() and fwrite(). fread() takes a pointer to a location in memory where adequate space has been allocated, the size of a single unit of the type of data you are going to be reading in to that location from a file, the number of those individual types from the previous parameter, and finally, the stream that you are reading from. I have learned that it basically copies the data from the file to the location pointed to by the first parameter... fwrite() works in a similar manner, but basically copies the number of data items starting with the memory location pointed to by the first parameter. I have noticed that both functions work sequentially, and basically seem to use a starting point in memory and the number of items of the specified size. What about data structures that are not put together like arrays. It seems that the way these functions work, they are good only for data structures like arrays that are lied out one after another in memory. A linked list for example is not linked due to the way it is laid out. In memory, it could be all over the place, but it is intact because each node contains a pointer to the next structure. In an instance like this, simply providing a pointer to the first node of the linked list does not guarantee that directly after that node in memory, node #2 will follow. Are there any functions built into C that can handle writing structures that are not sequentially laid out in memory to a binary file? Any suggestions would be much appreciated.



LinkBack URL
About LinkBacks


