/*使用库函数strstr()编程如下*/
#include<stdio.h>
#include<string.h>
main( )
{
int i,times=0;
char s[80]="There are 2 pens in your pencil-box.";
char sub[]="pen", *find=s;
for(i=0; ;i++)
{
find = strstr(find,sub);
if(find==NULL)break;
times++;find++;
}
if(times)
printf("\"%s\" occurs %d times\n",sub,times);
else
printf("\"%s\" not exists at all\n",sub);
}
#include<stdio.h>
#include<string.h>
main( )
{
int i,times=0;
char s[80]="There are 2 pens in your pencil-box.";
char sub[]="pen", *find=s;
for(i=0; ;i++)
{
find = strstr(find,sub);
if(find==NULL)break;
times++;find++;
}
if(times)
printf("\"%s\" occurs %d times\n",sub,times);
else
printf("\"%s\" not exists at all\n",sub);
}

落霞与孤鹜齐飞,秋水共长天一色! 心有多大,路有多宽。三教九流,鸡鸣狗盗。兼收并蓄,海纳百川。