0

My homework assignment is to read a file, store in target words (delimited by #) and replacement words (also delimited by #) and original strings (they do not have #).

Also I could not assume max str length, or max # of words.

For example:

#uic#e# // uic = target string   e = replacement string
juice  // find substring "uic"  and replace it with 'e' resulting in "jee"
quicken  // qeken
quiche   // qehe
uicuicuick // eeek
#pp##   // pp = target string   nothing = replacement string
apples  //ales
copper  // coer
bopped  //boed
#t#tttttt#  // t = target string   tttttt = replacement string
tut tut // ttttttutttttt ttttttutttttt
tttttttttttttttttttttttttttttttttttttttttttttttttttt // last string = 
                                                 //# of t's * 6

I've done EVERYTHING besides figuring out how to use the target string w/the replacement string. Is it possible to do it with strstr? I know it points to the first occurrence but is it possible to make it point to every occurrence in a string? Please show me using pseudocode. Thank you!

exexzian
  • 7,782
  • 6
  • 41
  • 52
ShadyBears
  • 3,955
  • 13
  • 44
  • 66

1 Answers1

0

Using strstr() to find the address of the first occurrence, call it address, then you could use strstr() again on address + strlen(target_string) to find the occurrences in the rest of the string.

dzop
  • 11
  • 1