GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 11-Jul-2008, 09:33
ForeverYoung ForeverYoung is offline
New Member
 
Join Date: Jul 2008
Posts: 9
ForeverYoung is on a distinguished road

Help with adding details to a file


Hi all, I need some help with c++ .txt files, I just need a general description of how should I go about doing what I need to do...

Sample txt file:
Code:
11/11/2008 <record1> <record2> <record3>

After processing it, I need to add details at the back of the records like so:
Sample txt file:
Code:
11/11/2008 <record1><extra details> <record2><extra details> <record3><extra details>

How do I go about doing this?
  #2  
Old 11-Jul-2008, 09:48
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,218
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Help with adding details to a file


Quote:
Originally Posted by ForeverYoung
... I just need a general description...

Here's how I might approach it:
Code:
1. Open the original file for reading. 2. Create (open) a brand new file for writing. 3. Perform the following for each line in the input file: Read the line from the input file Make changes/additions to the line's contents Write the altered line to the output file 4. Close the input file and output file. 5. Rename the original input file to something else. That means that your original file has been backed up. 6. Rename your output file so that it has the same name as your original input file.

Regards,

Dave
  #3  
Old 11-Jul-2008, 10:14
ForeverYoung ForeverYoung is offline
New Member
 
Join Date: Jul 2008
Posts: 9
ForeverYoung is on a distinguished road

Re: Help with adding details to a file


Cool, I was thinking along the same lines as that, I wanted to get a second opinion in case my way was wrong.

Also, let's say my output file has to be the same name as my original input file and I do not need to keep a copy of the original input file:

Step 1- Read in original file (sample.txt)
Step 2- Produce file with extra details (temp.txt)
Step 3- Rename temp.txt to sample.txt

Is there code/way to rename temp.txt to sample.txt? I confess I do not know how to do it
  #4  
Old 11-Jul-2008, 12:05
dlp dlp is offline
Member
 
Join Date: May 2006
Posts: 157
dlp has a spectacular aura about

Re: Help with adding details to a file


An old C function called Rename:

http://www.cplusplus.com/reference/c...io/rename.html
  #5  
Old 11-Jul-2008, 20:33
ForeverYoung ForeverYoung is offline
New Member
 
Join Date: Jul 2008
Posts: 9
ForeverYoung is on a distinguished road

Re: Help with adding details to a file


Boy that's a very cool function!

And one last question, what code should I use if I want to completely delete a .txt file?
  #6  
Old 11-Jul-2008, 20:44
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,218
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Help with adding details to a file


Quote:
Originally Posted by ForeverYoung
...what code should I use if I want to completely delete a .txt file?

I respectfully suggest you get a book or find an on-line reference to standard C library functions. Dlp gave one possibility; here's another: http://www.cppreference.com/

Click on the link Standard C I/O

There is a list of all of the functions in the standard C I/O library. Do you see "remove?"

I mean, it's always OK to ask, but wouldn't you like to find out how to learn these things yourself?

Regards,

Dave
  #7  
Old 14-Jul-2008, 08:45
ForeverYoung ForeverYoung is offline
New Member
 
Join Date: Jul 2008
Posts: 9
ForeverYoung is on a distinguished road

Re: Help with adding details to a file


I'm sorry ><, I used cplusplus.com but I couldn't find that "remove" function, I was looking out for something like "delete" or "destroy" =x

Anyhow, thanks guys
 
 

Recent GIDBlogProgramming ebook direct download available by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB 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
Airport Log program using 3D linked List : problem reading from file batrsau C Programming Language 11 29-Feb-2008 08:44
After execution - Error cannot locate /Skin File? WSCH C++ Forum 1 05-Mar-2005 21:03
CD burner wont burn!! robertli55 Computer Hardware Forum 1 18-Jun-2004 11:53
Yet another CD burner problem: Lite-On LSC-24082K Erwin Computer Hardware Forum 1 22-May-2004 12:28
CD Buring Failed skanth2000 Computer Hardware Forum 1 15-Nov-2003 04:52

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 01:04.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.