Editing exsiting files... Please help [Archive] - C Board

PDA

View Full Version : Editing exsiting files... Please help


Unregistered
06-22-2002, 11:37 AM
At the moment i am makeing a game where files are used extensivley, but i have a problem. At the moment i am using fin and fout statments to my advantage, and all is well. I have one problem though, I do not know how to EDIT existing files. For instance

Here is file "example.txt"
Welcome
is
an
exammple
file


Seems funky right? Now how would i, using the program, insert "this" in line two without changing the rest of the file and how would i right "example" over "exammple"?

Please help!

sean345
06-22-2002, 12:44 PM
What you could do is read in the entire file. Store it to a string or a double dimensioned array for each line. So String[0] is line 1. The first char in line one would be String[0][0]. String would be a char**. Then you can edit the parts you want and go back and write over the entire file with what you want.

- Sean

Unregistered
06-22-2002, 12:58 PM
Thanx for the idea, but the files that i am going to be use could be long, VERY LONG, as in 100+ line and I dont think it would be too easy on the computer to have a 100 x 100 file... is there and way i can just insert/edit 1 line?

P.S. I would be fine with using a command other than fin/fout

sean345
06-22-2002, 01:39 PM
I really do not know if that is possible. Take a look at the fseek() function, I think it my help with what your doing. Sorry.

- Sean