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

Help with file management. Please help!!

Tom
OK I'm trying to go to the end of a file and delete the contents
upwards until I meet a certain character. How can I do this? (NOTE:
I'm using text files)
Jul 19 '05 #1
2 3001
If you don't mind brute force you can do:

farthest_pos = 0
open file
while not eof
read char
if it is target char
farthest_pos = current_pos
wend
rewind
copy from 0 to farthest_pos to temp file
close file
remove file
rename temp file to original file
"Tom" <sn***@hotmail.com> wrote in message
news:78**************************@posting.google.c om...
OK I'm trying to go to the end of a file and delete the contents
upwards until I meet a certain character. How can I do this? (NOTE:
I'm using text files)

Jul 19 '05 #2
Tom wrote:
OK I'm trying to go to the end of a file and delete the contents
upwards until I meet a certain character. How can I do this? (NOTE:
I'm using text files)


This is very painful (at least to most operating systems). From
reading articles in news:comp.lang.c and news:comp.lang.c++, there
is no constant or standard method to position a file to a offset
measured in units of characters. With this knowledge, backspacing
through a file character by character is not portable. A case in
point is "\r\n": is it one or two characters?

Another rule about files that is hindering your activitiy is that
files don't shrink. You really can't "delete" a character in the
middle or end without creating a new file. The standard idiom
for delete sections in a file is to copy all the "wanted" stuff
to a new file and delete the old file.

Given the above points, a likely process is to read the entire
file into a container, then seach the container. A stack seems
very appropriate. This algorithm could be modified by searching
the file for the given character and saving the file positions.
After the file is processed, rewind it and copy everything up
to the last position saved to a new file. Two passes of reading
the file are required; but less memory is consumed. This latter
technique is portable since you are saving the position of a file
which is generated by the OS and not modifying.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library

Jul 19 '05 #3

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

Similar topics

21
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
1
by: Tim Marshall | last post by:
I'm putting together my first help file (using Easy Help, http://www.easyhelp.com/). So far, so good. I'm able to use the Help File and Help Context ID to have things from my help file pop up...
1
by: Christina Feichter | last post by:
Hello All How can i start a help-file like help.chm? Thanks
1
by: S. van Beek | last post by:
Dear reader, In the form property "Help File" there is the possibility to specify a .chm help file. This help file can be created with "HTML Help Workshop". According the instructions...
1
by: s | last post by:
I need to coordinate file management between three computers. Users need to enter all file names and would like to store file names,date changed,person changed etc. into a database. User...
4
by: str1ker | last post by:
Hi, I'm new on this website as you may already know. I've created a nifty calculation program (not a calculator, a simultaneous equation solver). I've also created a help file named 'help.chm'. ...
5
by: yazwas | last post by:
Hi, I'm looking for a file management library in C++, i.e library that has createfile, readfile, movefile, ...etc I need it for linux espically, it no general one is available does anyone have...
1
by: systemonkey | last post by:
I have a lot of huge files on a server and I can't risk getting deleted by anyone. What I have been doing is I create a ftp account for users and create a hardlinks to the original file in case...
2
jkmyoung
by: jkmyoung | last post by:
Does anyone know of good software to create a windows help file? .hlp There seems to be tons out there, but the ones lately I've tried so far aren't that great. Looking for both free and...
0
by: lgwapnitsky | last post by:
I am writing an Outlook add-in that needs to fire when a PST is added/removed. I have successfully fired the event using the AddStore and RemoveStore functions, as well as when I use the "Open ->...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

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.