1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

file operations...

Discussion in 'C' started by ceus, Jan 16, 2007.

  1. ceus

    ceus New Member

    Joined:
    Oct 16, 2006
    Messages:
    22
    Likes Received:
    0
    Trophy Points:
    0
    hello friends,
    i want to search a string in a file and replace that with the other string ?? can anyone gimme a code for this....
    thanks...
     
  2. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    By far the easiest method (presuming that the replacement may be longer) is to read the file up to the string, writing it to a temp file in the process, put the replacement string in the temp file, copy the remainder to the temp file, delete the original, and rename the temp with the original name. Editing a file "in place" is not a trivial undertaking unless you get into raw file handling instead of using the OS.
     
  3. ever_thus

    ever_thus New Member

    Joined:
    Jan 3, 2007
    Messages:
    53
    Likes Received:
    0
    Trophy Points:
    0
    You might want to cosider doing this in Perl. It will be far easier than in C/C++.
     
  4. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    I would say, just as a personal observation, that when a person is seeking solutions for a particular language, they are not extremely interested in being directed to use another. Difficulty in understanding a particular part of a language is not often best attacked by throwing in the towel and switching to Perl, Python, or Haskell, despite their sometimes easier approaches, via added abstractions.
     
  5. ceus

    ceus New Member

    Joined:
    Oct 16, 2006
    Messages:
    22
    Likes Received:
    0
    Trophy Points:
    0
    thanks DaWei,
    i have done that part what u told..i.e. copying that to a sting and replacing there and then fwrite() to the original file... but how can i do that without copying ???
    and one more thing.. sorry if it is silly.. i cant see the threads started by me !!!!! what to do for this... thats y by mistake have posted the thread twice....
     

Share This Page