編寫函數int fun(char s1,char *s2),在字符串s1中統計字符串s2出現的次數並返回。若s2在s1中未出現,則返回0。例如:
若輸入的字符串s1為:abaaAabcaabbabca,字符串s2為:ab ,則程序輸出:n=4
若輸入的字符串s1為:abaaAabcaabbabca,字符串s2為:abd,則程序輸出:No find
答案: int fun(char *s1, char *s2)
{
int i, j, len1 = strlen (s1), len2 = strlen (s2), n=0;
for (i=0; i<=len1-len2; i++)
{
for (j=0; j<len2; j++)
{
if ((s1+i+j) != *(s2+j))
break;
}
if (j == len2)
{
i += j-1;
n++;
}
}
return n;
}
求每行的注釋!!!!!!!!!!1