Board index » cppbuilder » how to insert data in a file

how to insert data in a file


2006-06-29 05:47:57 PM
cppbuilder6
Hi all,
This should be a basic question but I just don't know.
When writing file, I don't know the content (the length of the following
data) for the first 4 bytes, then I write 0x00000000 at the beginning of the
file and continue to write the data. after finish writing the data, I need
to change the very beginning 4 bytes to real length.
Can anybody help me? Thanks in advance.
Zhan Wei Ming
 
 

Re:how to insert data in a file

"zhan wei ming" < XXXX@XXXXX.COM >wrote:
Quote
This should be a basic question but I just don't know.
Basic random access file question, yes.
Quote
When writing file, I don't know the content (the length of the following
data) for the first 4 bytes, then I write 0x00000000 at the beginning of the
file and continue to write the data. after finish writing the data, I need
to change the very beginning 4 bytes to real length.

Can anybody help me? Thanks in advance.
Seek to the start of the file (depending on the method you are using to
write to the file, there will be a function called seek() or fseek() or
seekp() or similar).
Write the 4 bytes.
This requires the file to have been opened for random access. Check that
if it's not working.
Alan Bellingham
--
Me <url:mailto: XXXX@XXXXX.COM ><url:www.doughnut.demon.co.uk/>
ACCU - C, C++ and Java programming <url:accu.org/>
The 2006 Discworld Convention <url:www.dwcon.org/>