若在字符串haystack中找到了子字符串needle,就返回其在母字符串中的起始位置,若没找到就返回-1
int strStr(char* haystack, char* needle) {
int len1 = strlen(haystack);
int len2 = strlen(needle);
int len = len1 - len2;
int i, j;
for (i = 0; i <= len; i++)
{
for (j = 0; j < len2; j++)
{
if (needle[j] != haystack[i+j])
{
break;
}
}
if (j == len2)
{
return i;
}
}
return -1;
}