-3
我需要編寫自己的函數實現,該函數在另一個字符串(文本)中查找字符串(word1),並用第三個字符串(word2)替換文本中word1的所有實例。 這是我迄今爲止;findAndReplace函數的實現
void findandreplace(char text[],const char word1[], const char word2[])
{
char *start;
char *end;
start=strstr(text,word1);
end=start;
if (strcmp(text,start))
{
end+=strlen(word2);
strcpy(&text[end-start+1],&text[(int)start]);
strcpy(text,word2);
findandreplace(end,word1,word2);
}
if (!strcmp(text,start))
{
end++;
findandreplace(end,word1,word2);
}
if (!text)
{
return;
}
}
我確信我在寫這篇文章時犯了很多錯誤,但請記住我基本上是一個完整的noob。任何幫助指出錯誤和可能的更正將不勝感激。
這將有很大的幫助,如果你想開始修復您的壓痕。 –
歡迎來到StackOverflow。請閱讀並遵守幫助文檔中的發佈準則。 [最小,完整,可驗證的示例](http://stackoverflow.com/help/mcve)適用於此處。在發佈代碼*和*準確描述問題之前,我們無法有效幫助您。就我們所看到的,您還沒有嘗試運行您的代碼,因此尚未遇到任何實際問題供我們解決。 – Prune
http://stackoverflow.com/a/35476087/971127 – BLUEPIXY