472,958 Members | 2,436 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 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 2986
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
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.