473,386 Members | 1,873 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,386 software developers and data experts.

delete from a file, maybe overwrite!?

I have a binary file, and I need to delete a specific number of characters
in it.
The file contains records, each record has a specific length.
So the way I wanna handle deleting is that I will overwrite the record I
want to delete with the last record in the file, then actually delete that
last record in the file. the problem Im having is how to delete that last
record in the file.

Suppose each record is of length 43, then I have something like:

fstream inoutData;

inoutData.open("this_file.txt", ios::binary | ios::in | ios::out);

char read_this[44];

inoutData.seekg(-43,ios::end);

inoutData.read(read_this,43);

read_this[43] = '\0'; // now read_this contains the last record

inoutData.seekp(-43,ios::end);

inoutData.write("",43); // << here, how I can delete the last record???
Oct 2 '05 #1
1 4430
"Someonekicked" <so***********@comcast.net> wrote in message
news:4b********************@comcast.com...
I have a binary file, and I need to delete a specific number of characters
in it.
The file contains records, each record has a specific length.
So the way I wanna handle deleting is that I will overwrite the record I
want to delete with the last record in the file, then actually delete that
last record in the file. the problem Im having is how to delete that last
record in the file.

Suppose each record is of length 43, then I have something like:

fstream inoutData;

inoutData.open("this_file.txt", ios::binary | ios::in | ios::out);

char read_this[44];

inoutData.seekg(-43,ios::end);

inoutData.read(read_this,43);

read_this[43] = '\0'; // now read_this contains the last record

inoutData.seekp(-43,ios::end);

inoutData.write("",43); // << here, how I can delete the last record???


Hello

To delete the last record is equivalent to setting a new end-of-file. AFAIK
this is OS related and non standard.

If you were using MS Windows API, I would suggest looking @ SetEndOfFile().

Now in your case, if your records all have the same size, you can instead of
delete a record, you simply mark the record as free or as deleted, then
whenever you want to add, you search for that marker and write new record
there.

Hope that helps,
Elias
Oct 3 '05 #2

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

Similar topics

2
by: andy | last post by:
I am having an issue with the way SQL server deletes data. I am trying to delete data from the DB and have it completetly gone. Here is what I did 1. added a table with a row of image data...
2
by: Paul LAURENT | last post by:
Hi everybody, I am using the STL "ofstream" class. I open a file using "ofstream" in update at the end mode ("ate"), I can read and write my file correctly. => What I would like to do is...
8
by: Dong Ge | last post by:
Hi! I am a beginner of C. I want to delete some characters or a whole line in a text file. I have tried the "fprintf", "fputs", "fwrite", but no one of them can run rightly. In the below...
6
by: Poppy | last post by:
I use the following code to append a line of text to a text file : Dim myFILENAME As String = Server.MapPath("/ABACUS/cvdocs/" & fileName) Dim objStreamWriter As StreamWriter objStreamWriter =...
1
by: Learner80 | last post by:
Hello, I would like to find a way to programmatically delete the index.dat files from IE, or at least be able to overwrite the index.dat with blanks... I understand that the OS treats this file as...
0
by: smanisankar | last post by:
hi, the following is the full page code for uploading a file to server. since i got no idea to overwrite the file, i want delete the file if the file is already uploaded. i got the folder name...
1
by: Kyote | last post by:
I'm wanting to copy/move files from 1 directory to another in my program. I'm even doing a bit of renaming to help these specific files conform slightly to my preferred naming conventions to help...
26
by: Army1987 | last post by:
Is this a good way to check wheter a file already exists? #include <stdio.h> #include <stdlib.h> int ask(const char *prompt); typedef char filename; int main(int argc, char *argv) { FILE...
6
by: Annalyzer | last post by:
My database must produces a .csv file with a header line that is different from the detail lines. This .csv file contains a monthly report to an outside agency and is uploaded online so it must...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.