help with fwrite()

T

T. Crane

Hi all,

I'm trying to use successive calls to fwrite() to write out to a file.
I don't have any trouble opening the file or getting everything I need
in there, but I do notice a peculiarity about it that I will describe.

I call it like so:

fwrite(&buffer, 14, 1, filestream)

I then call it may times in a loop where I've set my buffer pointer to
change with each iteration so that it writes the data I want it to
write. When I go into debug mode, I can then open up the file in a
reader and watch it grow, so to speak. The odd thing is that it
doesn't seem to grow with every call to fwrite(). It only seems to
grow in 4 kB jumps. Does anyone know why this would be?

FYI - I'm using Windows XP and my compiler is Visual C++ 6.0.

thanks in advance,
trevis
 
A

Alf P. Steinbach

* T. Crane:
Hi all,

I'm trying to use successive calls to fwrite() to write out to a file.
I don't have any trouble opening the file or getting everything I need
in there, but I do notice a peculiarity about it that I will describe.

I call it like so:

fwrite(&buffer, 14, 1, filestream)

I then call it may times in a loop where I've set my buffer pointer to
change with each iteration so that it writes the data I want it to
write. When I go into debug mode, I can then open up the file in a
reader and watch it grow, so to speak. The odd thing is that it
doesn't seem to grow with every call to fwrite(). It only seems to
grow in 4 kB jumps. Does anyone know why this would be?

Buffering.


Cheers, & hth.,

- Alf
 
P

Pete Becker

I'm trying to use successive calls to fwrite() to write out to a file.
I don't have any trouble opening the file or getting everything I need
in there, but I do notice a peculiarity about it that I will describe.

I call it like so:

fwrite(&buffer, 14, 1, filestream)

I then call it may times in a loop where I've set my buffer pointer to
change with each iteration so that it writes the data I want it to
write. When I go into debug mode, I can then open up the file in a
reader and watch it grow, so to speak. The odd thing is that it
doesn't seem to grow with every call to fwrite(). It only seems to
grow in 4 kB jumps. Does anyone know why this would be?

Output streams are usually buffered by the runtime library, and 4k is
certainly a reasonable size for that buffer. The contents of the buffer
only get written to disk when the buffer gets full or you close the
file.
 
T

T. Crane

OK that's pretty much what I guessed, but I thought I'd ask.

thanks for the confirmation.
 
J

Jalen

OK that's pretty much what I guessed, but I thought I'd ask.

thanks for the confirmation.

One thing i want to know is whether there is a way to change the
buffer size (currently 4K)?

Thanks
Jalen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

strace of fwrite 0
Help with Loop 0
Help 1
Help with C negative indexes 2
C fwrite equivalent in ruby 3
Help with Github??? 2
Help with array 4
fwrite 10

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top