0

我的家庭作业是读取一个文件,存储目标词(用# 分隔)和替换词(也用# 分隔)和原始字符串(它们没有#)。

我也不能假设最大 str 长度或最大单词数。

例如:

#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

除了弄清楚如何使用带有替换字符串的目标字符串之外,我已经完成了一切。有可能做到strstr吗?我知道它指向第一次出现,但是否可以让它指向字符串中的每一次出现?请告诉我使用伪代码。谢谢!

4

1 回答 1

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.

于 2013-02-14T05:04:12.473 回答