,如果我有一個布爾原型,如bool repeat(const char *S, char *P)
我要搜索S爲同一序列爲P,&返回true,如果有匹配,例如:布爾C-串序列 - 報告匹配
char *this = "ABCDEFGH";
bool found;
found = count(this, "DEF"); // will be true
found = count(this, "FED"); // will be false
我當前幼稚溶液是
bool count (const char *S, char *P){
bool found;
int i = 0;
if (S[0] = P[0] && S[1] = P[1] && S[2] = P[2]) found = true;
else i + 1;
我可以使用語法S [0 + i]和等繼續尋找陣列中,如果第一構件不匹配?
任何洞察力是讚賞。謝謝。
'char * this =「ABCDEFGH」;'?這甚至是合法的嗎? – IInspectable
@IInspectable是的。看到[這篇文章。](http://programmers.stackexchange.com/questions/249554/assigning-strings-to-pointer-in-c) –
@AhmedAkhtar:這個問題是關於[標籤:C++],雖然, 'this'是一個保留關鍵字。 – IInspectable