Thread: Editing exsiting files... Please help

  1. #1
    Unregistered
    Guest

    Editing exsiting files... Please help

    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!

  2. #2
    Registered User sean345's Avatar
    Join Date
    Mar 2002
    Posts
    346
    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
    If cities were built like software is built, the first woodpecker to come along would level civilization.
    Black Frog Studios

  3. #3
    Unregistered
    Guest
    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

  4. #4
    Registered User sean345's Avatar
    Join Date
    Mar 2002
    Posts
    346
    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
    If cities were built like software is built, the first woodpecker to come along would level civilization.
    Black Frog Studios

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading .dat files from a folder in current directory...
    By porsche911nfs in forum C++ Programming
    Replies: 7
    Last Post: 04-04-2009, 09:52 PM
  2. Linking header files, Source files and main program(Accel. C++)
    By Daniel Primed in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2006, 11:46 AM
  3. Multiple Cpp Files
    By w4ck0z in forum C++ Programming
    Replies: 5
    Last Post: 11-14-2005, 02:41 PM
  4. Folding@Home Cboard team?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 398
    Last Post: 10-11-2005, 08:44 AM
  5. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM