Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 22nd, 2007, 7:12 PM   #1
rhm54
Newbie
 
Join Date: Oct 2007
Posts: 2
Rep Power: 0 rhm54 is on a distinguished road
Unhappy Help with fstream to a text file

Alright here is my dilemma. I have a program that is supposed to go out an look at a text file and determine if it has null information in one field. If it does have null information in that field another function needs to come back and overwrite the entire record as null. Fairly easy so far.

Now after that process I need to copy the non null contents of the data file to new file with the same name as the old file. Then delete the old file. This is the part that I don't understand. I guess I need to copy them to a temp file and then delete the old file but I don't know how to do this. All help is appreciated.
rhm54 is offline   Reply With Quote
Old Oct 22nd, 2007, 7:44 PM   #2
SamReidHughes
Newbie
 
Join Date: Oct 2007
Posts: 13
Rep Power: 0 SamReidHughes is on a distinguished road
Re: Help with fstream to a text file

Well you could copy it to a temp file and delete the old file, or just move it to the old filename, after all of it has been read in. Or you could move the old filename to a temporary location and go from there. What difference does it make to you?
SamReidHughes is offline   Reply With Quote
Old Oct 22nd, 2007, 7:47 PM   #3
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Re: Help with fstream to a text file

Why bother to write to the original file when you're going to immediately throw away what you've written? Open a temp file. Read a record from the originial. If it has the null field, discard it, otherwise write it to the temp file. When you've finished, delete the original and rename the temp to the original name.

If you're saying you don't know how to delete and rename files, I would suggest a visit to the help files for your compiler and OS.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Oct 22nd, 2007, 8:08 PM   #4
rhm54
Newbie
 
Join Date: Oct 2007
Posts: 2
Rep Power: 0 rhm54 is on a distinguished road
Re: Help with fstream to a text file

I am feeling really dumb and need some help in a major way. I don't even know how I am supposed to delete the old file. What command would I use? Also I am now even having problems with the first part. What command can I use for the isNull() function to return the position of the record to be overwritten by the writeNullToFile() function?
rhm54 is offline   Reply With Quote
Old Oct 22nd, 2007, 8:11 PM   #5
SamReidHughes
Newbie
 
Join Date: Oct 2007
Posts: 13
Rep Power: 0 SamReidHughes is on a distinguished road
Re: Help with fstream to a text file

Command? There's no command. You have to write it yourself.

What format are the text files in?
SamReidHughes is offline   Reply With Quote
Old Oct 22nd, 2007, 8:13 PM   #6
Jabo
Not a user?
 
Join Date: Sep 2007
Posts: 272
Rep Power: 2 Jabo is on a distinguished road
Re: Help with fstream to a text file

just do a google for file io for your language
Jabo is offline   Reply With Quote
Old Oct 22nd, 2007, 9:39 PM   #7
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Re: Help with fstream to a text file

I'm guessing the language is C++ .

To the OP: You aren't paying attention to your responses. If you're going to indentify a record as being tossable by some field, overwrite the entire record with something that represents nulls, the read it back and throw it away, there's no point in overwriting it.

Read the file record by record. You'll have to know your format in order to do that properly. Check the field that represents a discardable record. If the record is discardable, ignore it and read the next record. Otherwise, write the record to a temp file.

Wash, rinse, repeat until the operation is done. Delete the original file (see 'remove'). Rename the temp file to the original file name (see rename).

All this is relatively trivial (depending on your format). If it's news to you, you might be biting off more than you can chew without a little more practice.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic form from text file. randum77 Visual Basic .NET 4 Apr 24th, 2007 11:39 AM
Adding more info to a text file without erasing crawforddavid2006 C# 2 Apr 11th, 2007 2:10 PM
Text File split tayspen C# 17 Nov 4th, 2005 8:55 AM
How to read unknown total of int data from text file to a 2-dim array in C ladyscarlet99 C 2 Sep 9th, 2005 2:28 AM
How to read unknown total of int data from text file to a 2-dim array in C++? ladyscarlet99 C++ 2 Sep 9th, 2005 1:01 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:36 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC