C 如何使用str查找多个事件并替换?
我的家庭作业是读取一个文件,存储目标词(用#分隔)和替换词(也用#分隔)以及原始字符串(它们没有#) 我也不能假设最大str长度,或者最大单词数 例如:C 如何使用str查找多个事件并替换?,c,strstr,C,Strstr,我的家庭作业是读取一个文件,存储目标词(用#分隔)和替换词(也用#分隔)以及原始字符串(它们没有#) 我也不能假设最大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 uicuicu
#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执行此操作?我知道它指向第一个事件,但有可能让它指向字符串中的每个事件吗?请告诉我使用伪代码。谢谢大家! 使用strstr()查找第一次出现的地址,将其称为
address
,然后您可以在address+strlen(target_string)
上再次使用strstr()查找字符串其余部分的出现处。“请使用伪代码显示我”-否。你需要这样做,并写一些代码…给我们看你的代码(刚刚看到你的编辑)。我不是要求作业。我在问是否有可能使用strstr指向另一个事件,如果是,有人能给我看一下它的伪代码吗。