define _CRT_SECURE_NO_WARNINGS
#include
#include
#include
#include
#include

char my_strstr(char src, char dest)
{
char
fsrc = src;//用作于遍历循环的指针
char rsrc = src;//记录每次相同的首地址
char
tdest = dest;
while (fsrc)
{
rsrc = fsrc;
while (
fsrc == tdest && fsrc != ‘\0’)
{
fsrc++;
tdest++;
}
if (*tdest == ‘\0’)
{
return rsrc;
}
//回滚
tdest = dest;//目标字符串更新到起始位置
fsrc = rsrc;
fsrc++;
}
return NULL;
}

int main1()
{
char str = “11abcd111122abcd333abcd3322abcd3333322aq”;
char ch[] = “abcd”;
char
p = my_strstr(str,ch);
int count = 0;//记录个数
while (p != NULL)
{
count++;
p += strlen(ch);
p = my_strstr(p, ch);
}
printf(“abcd在字符串中出现:%d次\n”,count);
return 0;
}
int main()
{
char str = “11abcd111122abcd333abcd3322abcd3333322aq”;
char ch[] = “abcd”;
char
p = my_strstr(str, ch);
int count = 0;//记录个数
do
{
if (p)
{
count++;
p += strlen(ch);
p = my_strstr(p, ch);

  1. }<br /> } while (p);<br /> printf("%d\n", count);<br /> return 0;<br />}