string search and copy in a file !

This is a discussion on string search and copy in a file ! within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by Salem Why don't you just do read from one file, write to another file and stop monkeying ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Page 3 of 3 FirstFirst 123
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, 05:44 PM
  3. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 09: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21