Replacing a word into other word

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sri.mohankumar@gmail.com

    Replacing a word into other word

    hi
    i want replace one word to another in a file .i am trying to use in
    gets

    by
    SRI

  • Nick Keighley

    #2
    Re: Replacing a word into other word

    sri.mohankumar@ gmail.com wrote:
    [color=blue]
    > i want replace one word to another in a file .i am trying to use in
    > gets[/color]

    gets() does not read from a file. It is also fatally flawed in its
    handling of overflows. *Never* use gets(). Use fgets() to read line.
    Use strstr() to find the word. The substitution is trickier.
    Consider this line:-

    "small elephants hate elephants optics"

    To replace "hate" with "love":-
    find the "hate"
    write the line to another file (use fputs()) until you
    reach "hate"
    write "love"
    write the rest of the line

    Give it a try. If you get stuck post what you've written.


    --
    Nick Keighley

    Comment

    • Zoran Cutura

      #3
      Re: Replacing a word into other word

      sri.mohankumar@ gmail.com wrote:[color=blue]
      > hi
      > i want replace one word to another in a file .i am trying to use in
      > gets[/color]

      So what is your question?
      --
      Z (zoran.cutura@w eb.de)
      "LISP is worth learning for the profound enlightenment experience
      you will have when you finally get it; that experience will make you
      a better programmer for the rest of your days." -- Eric S. Raymond

      Comment

      Working...