Thread: please help!...find and replace

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    <<Sorry about any confusion getting rid of the double post to both the C and C++ boards, merging replies (in the C thread), and moving this to a single thread on the C++ board.>>
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    15
    do i do some sort of loop or if? I really have no idea!! and i think it shows!!

  3. #3
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Are you guaranteed that the replacement text will be no bigger than the find text? If not, it would seem that you may need to venture towards dynamic allocation. Well, unless you've got a "large enough" buffer to contain any possible text after replacement. Is it safe to make that assumption?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  4. #4
    Registered User
    Join Date
    Oct 2006
    Posts
    15
    no, the word i have to find is 'be' and the word i have to replace is 'there'. So they are not the same size.

  5. #5
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    So... are you familiar with dynamic allocation? Or do you have the "large enough" assumption?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  6. #6
    Registered User
    Join Date
    Oct 2006
    Posts
    15
    i have not heard of that...so iguess i would have to go with the 'large enough' assumption...what ever that is!!

  7. #7
    Registered User
    Join Date
    Oct 2006
    Posts
    15
    please dont abandon me now! How do i do the find and replace stuff?

  8. #8
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    *sigh* I love it when students are taught how to overflow buffers.

    Find text with strstr.
    Copy text with strcpy or memcpy.
    Move the remaining text with memmove.
    Lather, rinse, repeat (if necessary).
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  9. #9
    Registered User
    Join Date
    Oct 2006
    Posts
    15
    ok...so how do i code that

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to find and replace a string in a file
    By salzouby in forum C Programming
    Replies: 13
    Last Post: 09-14-2010, 08:55 AM
  2. Find and replace within a string?
    By clancyPC in forum C Programming
    Replies: 3
    Last Post: 03-20-2009, 07:28 AM
  3. Find and replace
    By BobDole1 in forum C++ Programming
    Replies: 1
    Last Post: 04-12-2003, 10:06 PM
  4. Find and Replace Text Function
    By mart_man00 in forum C Programming
    Replies: 45
    Last Post: 03-13-2003, 10:21 PM
  5. find and replace command?
    By p0wp0wpanda in forum C Programming
    Replies: 2
    Last Post: 05-24-2002, 11:42 PM