473,410 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,410 software developers and data experts.

help with fwrite()

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
Feb 1 '08 #1
4 1905
On 2008-02-01 18:19:18 -0500, "T. Crane" <tr**********@gmail.comsaid:
>
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.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Feb 1 '08 #2
OK that's pretty much what I guessed, but I thought I'd ask.

thanks for the confirmation.

On Feb 1, 5:33 pm, Pete Becker <p...@versatilecoding.comwrote:
On 2008-02-01 18:19:18 -0500, "T. Crane" <trevis.cr...@gmail.comsaid:


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.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)
Feb 1 '08 #3
On 2ÔÂ2ÈÕ, ÉÏÎç7ʱ42·Ö, "T. Crane" <trevis.cr...@gmail.comwrote:
OK that's pretty much what I guessed, but I thought I'd ask.

thanks for the confirmation.

On Feb 1, 5:33 pm, Pete Becker <p...@versatilecoding.comwrote:
On 2008-02-01 18:19:18 -0500, "T. Crane" <trevis.cr...@gmail.comsaid:
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.
--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)
One thing i want to know is whether there is a way to change the
buffer size (currently 4K)?

Thanks
Jalen
Feb 2 '08 #4
On 2008-02-01 23:59:45 -0500, Jalen <ji***********@gmail.comsaid:
>
One thing i want to know is whether there is a way to change the
buffer size (currently 4K)?
Yes, there is. Look it up.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Feb 2 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: dont bother | last post by:
Hi Buddies, I am facing this problem and I dont know what to use as EOF in python: I want to read a file, and put all the individual words in a dictionary with their index: For example if the...
3
by: dont bother | last post by:
Hi, I have written this small piece of code. I am a brand new player of Python. I had asked some people for help, unfortunately not many helped. Here is the code I have: import email import...
9
by: Craig | last post by:
Hello friends at comp.lang.c, I'm trying to combine 2 strings with a newline character at the end to write to a file. When I view the file, the messages run together and some of the str string...
3
by: ern | last post by:
I'm writing to a file called "output.txt" It *should* contain floating point numbers delimited by semi-colons. Instead, it contains Chinese characters. /* HERE IS MY CODE */ FILE...
2
by: elisa | last post by:
Dear all, I have problems in writeing and reading a block of data (long array) with fread and fwrite. If I write and read an integer array, everything looks fine, but when I try long array, sth...
12
by: hemant.gaur | last post by:
I have an application which writes huge number of bytes into the binary files which is just some marshalled data. int len = Data.size(); //arrary size for (int i = 0; i < len; ++i)...
7
by: Inny | last post by:
Hello, Im trying To create A code In php That Does the Following: A. detects visiting users real ip address B. detects city and country C. detects browser type and version D. detects referrer...
5
by: it8ez2b | last post by:
I have no knowledge of how this work. I have this html template that I downloaded. It has a sign-in box that I would like for the username and password sent back to me to the password. txt file i...
3
by: vasu_7799 | last post by:
Hi, I have 2 structure. struct a { char cn; char tl; char roup; char rc; char adj;
9
by: xiao | last post by:
It always dumped when I tried to run it... But it compiles OK. What I want to do is to do a test: Read information from a .dat file and then write it to another file. The original DAT file is...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.