Thread: string search and copy in a file !

  1. #31
    Registered User
    Join Date
    Sep 2006
    Posts
    17
    Quote Originally Posted by Salem
    Why don't you just do read from one file, write to another file and stop monkeying around trying to do the near impossible of writing updates to the middle of a file
    If you read my code
    that's what I did !
    I just said
    "writes<<c;"
    that should put the string in the file where ever the put pointer is.
    but nothing happens !

  2. #32
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    But writes is an update file - you're busy reading AND writing it.
    Just simplify the problem to one file for reading, and one for writing.

    > fstream writes("new.txt",ios::out); // NO ios::in
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #33
    Registered User
    Join Date
    Sep 2006
    Posts
    17
    If I did that then I didn't do something new.
    But let me put it this way

    "writes" has data.
    I want to write the data found from "reads" in the last line of "writes" i.e add data to writes without deleting old data.
    I'm thinking about incrementing the put pointer till the eof
    but i'm not sure how to do that !

    Thanks for helping, much appreciated

  4. #34
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > I want to write the data found from "reads" in the last line of "writes" i.e add data to writes without deleting old data.
    Then by far the simplest is to copy the N-1 lines from the old version of "writes" to the new version of "writes".
    For the last line, read it from old "writes", make whatever changes you need to make then write the changed line to the new version of "writes".
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I'm not THAT good am I?
    By indigo0086 in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 10-19-2006, 10:08 AM
  2. Wrong Output
    By egomaster69 in forum C Programming
    Replies: 7
    Last Post: 01-28-2005, 06:44 PM
  3. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM
  4. string search question...
    By flightsimdude in forum C Programming
    Replies: 11
    Last Post: 09-24-2003, 09:11 PM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM