Re: Overwriting a portion of a binary file



mohammad.nabil.h@xxxxxxxxx wrote:

> I've been working on a database management system, and i have met a
> problem when i update a row, i found that fwrite() and _write, writes
> to the end of the file, even if i hade rewind() the file before it. As
> far as i can guess, they `append', i am looking for something that
> overwrites. of course i can't load the 'whole' file in memory, change
> it, then resave it again. the whole memory might not be enough.
>
> my code always insists on storing 'bar' after 'foo'. i want to save
> 'bar' instead of 'foo'
>
> here is a peek of my code :

We don't want a peek, we want a long, lingering look at the whole thing.


> void add_record(record* rec)
> {
> // m_db is a FILE*

Where is the code that created this FILE*?

> //fseek(m_db,0,SEEK_END);
> //fwrite(rec,record_size(),1,m_db);
> _write(fileno(m_db),rec,record_size()); // both function result in
> the same output

There is no _write() function in the C language.

> any help greatly appreciated

Post a complete, minimal, compilable program that demonstrates the
problem.



Brian

--
Please quote enough of the previous message for context. To do so from
Google, click "show options" and use the Reply shown in the expanded
header.
.



Relevant Pages

  • File is a special class?
    ... In order to make it's use as transparent as possible, i overloaded the 'require' method to search as well in the memory and this works fine at the moment. ... class Foo ... Creating a new Bar ... Should be type Foo and is: ...
    (comp.lang.ruby)
  • Re: semantic difference between [][] and **
    ... these two have the same meaning in memory. ... the definition of foo is illegal. ... dynamically and setting bar to have the same representation as foo. ... but have a different meaning. ...
    (comp.lang.cpp)
  • Re: Circular dependency - I think..
    ... When you create an instance of a FOO, ... > memory gets allocated for a new instance of BAR, ... > whether or not an exception gets thrown. ...
    (comp.lang.cpp)
  • =?iso-8859-1?Q?Re:_Survey:_C++_may_live_on_in_SOAs____=22its_very_diffic?= =?iso-8859
    ... So with an XML document like ... You'd have a "start Foo" event, ... Then a "Start bar" event, which you can process, then a "butz attribute" event, then a "End bar", and an "end Foo". ... On the other hand, only using a small window, and then moving back and forth, re-reading and re-parsing, may end up being even slower than keeping the whole document in memory. ...
    (comp.lang.java.advocacy)
  • Overwriting a portion of a binary file
    ... the whole memory might not be enough. ... my code always insists on storing 'bar' after 'foo'. ... void add_record ...
    (comp.lang.c)