#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//查找asd字符串
void main()
{
char *cz="asd";
char *p="qwewrasdoiuoiasdwqezasd";
int count=0;
char *p2=NULL;
p2=p;
while(*p2!='\0')
{
p2=strstr(p2,cz);//strstr() 函数搜索一个字符串在另一个字符串中的第一次出现。
//找到所搜索的字符串,则该函数返回第一次匹配的字符串的地址;
//如果未找到所搜索的字符串,则返回NULL。
if(p2!=NULL)
{
count++;
p2=p2+strlen(cz);//strlen求字符串长度
}
else
{
break;
}
}
printf("count:%d\n",count);
system("pause");
}
转载于:https://my.oschina.net/startstorm/blog/501186