![]() |
|
#1
|
||||
|
||||
Replacing N'th token in a file.Hey.
I want to replace the N'th token found at byte number N with a new token. I wrote the function to find the N'th character and it works just fine. Here is my code : CPP / C++ / C Code:
I need direction with how to insert my own token into the file. For example : If I have the file : my_file.txt ---------- first line second line and I want to use replace(my_file,5,"kobi") than the file would now be : my_file.txt ---------- firskobi line second line But, If I use replace(my_file,1,"kobi") the result would be : my_file.txt ---------- kobi line second line I came upon this issue while writing the assembler I told you guys about. Any reference or idea would be most welcome. Respect, Kobi. |
|
#2
|
|||
|
|||
|
Assuming the file you are trying to edit is arranged in certain structured manner when it was fist created, IMO one way to do it would be to read in the whole file into a runtime memory buffer (linked list of some sort), if the match for the token to be replaced is found, update the buffer and write the whole buffer back to the same file. Its as good as creating a new file with updated data.
This may not be the most efficient way of doing it but should get you started in the some direction. |
|
#3
|
||||
|
||||
|
Quote:
Thanks, but I am looking for an efficient way of doing the task. I want to update locally. |
Recent GIDBlog
US Elections and the ?Voter?s Responsibility? by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
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 |
| 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 |
| Re: Programming Techniques | WaltP | C Programming Language | 0 | 10-Mar-2004 00:56 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The