In standard C++, you would also include fstream.h and use fstreams. Two member functions of streams are seekp() and seekg(), which move the read and write offsets in the file, respectively. Check the details in any decent C++ book. Since fstreams derive from streams, you will be able to use these two functions with fstreams. NOTE: seekp(), (seek-put), and seekg(), (seek-get) move the put/get position in streams. Some stream types only use ONE such position for puts and gets, rather than 2 seperate positions. fstreams are an example. Bottomline: you can use either of these functions for fstreams to move the offset, regardless of whether or not you want to read or write to the file. If you have any questions, let me know. Bryan > > Is there a way in C++ ( using the iostream.h ) or in C ( using the > stdio.h and the like ) to control precisely how > data gets saved to a file. What I mean by this is, can I control exactly > at which offset within the file my data blocks will go. > > I need that, because I wrote a client that receives a file from a server. > In my implementation I am using UDP, so there is no guarantee about the > order in which the packets that constitute that file arrive. Every packet > though is numbered and its size (except for the last packet) is known. > > That lets me calculate exactly its starting and ending offset position > with in the file. > > It would be pretty neat if I could save the file to my disk, right away > as its packets keep on coming, based on the above calculation. I am sure > that is possible; unfortunately I don't know how to do it. > > I did some experimentation with fseek, but all I got was segmentation > faults. :( > > Any help would be appreciated, > mich >
