Thread: Question regarding File I/O

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    23

    Question regarding File I/O

    Hello all,

    What I would like to do is read from a file, one line at a time. I parse through each line to find the byte position that I need to enter text into.

    My question is:

    Would it be better programming to:
    1. Create a duplicate, temporary file to read the byte position from. Then I would open the file I want to write to at that position.

    or

    2. Have one file, read from it. Find the position I need to enter data. Then somehow rewind the position I am in that record and write data.

    Thanks,

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    I would use one file to do it. You can use the fseek() function to move around in a file.
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    Aug 2006
    Posts
    23
    That was my original idea...I ran into some trouble with that,

    User Salem suggested:

    In-place edits on text files isn't really the thing to do.

    Read a line from the input file
    Modify the line
    Write the line to the output file.

    When you're done, delete the old file and rename the new file.
    __________________
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.

    I was trying this option to take the line from a temp copy of the file , edit it, and write back the new line to the original file, then i have a shell script that erases the temp file.

    Sorry guys, I know c++ and shell scripts, c is new, but simialar to c++, but NOT really

  4. #4
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Oh, well yeah. I wasn't quite sure what you were doing. If you're replacing text with other text then I would definitely go with Salem's suggestion.
    If you understand what you're doing, you're not learning anything.

  5. #5
    Registered User
    Join Date
    Aug 2006
    Posts
    23
    thanks, I just wanted to make sure...

    lol I'm not suite sure what I'm doing either

    thanks for all your help!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. File i/o and ASCII question
    By muzihc in forum C Programming
    Replies: 13
    Last Post: 11-04-2008, 11:46 PM
  3. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  4. File I/O Question
    By Achy in forum C Programming
    Replies: 2
    Last Post: 11-18-2005, 12:09 AM
  5. Another dumb question about file i/o
    By Cobras2 in forum C++ Programming
    Replies: 23
    Last Post: 03-14-2002, 04:15 PM