0
初級問題: 我試圖做一個字符數組,包括功能,它應該比較2個陣列 - 圖案和文字,並返回文本,類似的指標之最:比較2個字符數組失敗
int main(int argc, const char * argv[])
{
int answer =0;
answer = match("viva","vviaaa");
printf("%d",answer);
return 0;
}
int match(char pattern[],char text[]) {
int i,t,counter=0,topCount=0,topIndex=0;
for (t=0;pattern[t]!= '\0'; t++) {
counter=0;
for (i=t; text[i]!='\0'; i++) {
printf("is %c = %c ?\n",pattern[i],text[i]);
if (pattern[i] == text[i]) {
counter++;
printf("yes\n");
}
if (pattern[i] =='\0') {
break;
}
}
if (counter>topCount) {
printf("%d > %d at index t: %d\n",counter,topCount,t);
topCount = counter;
topIndex = t;
}
}
return topIndex;
}
輸出(而非blacnk焦炭存在倒掛畫面包含「?」:
is v = v ?
yes
is i = v ?
is v = i ?
is a = a ?
yes
is � = a ?
2 > 0 at index t: 0
is i = v ?
is v = i ?
is a = a ?
yes
is � = a ?
is v = i ?
is a = a ?
yes
is � = a ?
is a = a ?
yes
is � = a ?
0Program ended with exit code: 0
你的問題是什麼? – FrankPl
輸出我檢查,它是根據代碼。現在請告訴,你在做什麼?什麼是信號問題陳述?什麼是差異? – mawia