zuoye
作者:互联网
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int cnt(char yuan[],char chazhao[])
{
int i=0,j=0;
int k;
int cot=0;int flag=0;
while(yuan[i]!=0)
{
if(yuan[i]==chazhao[0])
{
for(k=0;k<strlen(chazhao);k++)
{
if(yuan[i+k]chazhao[k])
{
flag++;
// printf(“flag=%d\n”,flag);
}
}
if(flagstrlen(chazhao))
{
cot++;
//printf(“cot=%d\n”,cot);
i=i+strlen(chazhao);
flag=0;
}
else
{
i++;
flag=0;
}
}
else
i++;
}
return cot;
}
int main()
{
char yuan[500];
gets(yuan);
char chazhao[500];
gets(chazhao);
int a=cnt(yuan,chazhao);
printf(“原字符串:%s 中查找的字符串:%s \n有%d个”,yuan,chazhao,a);
}
标签:cot,int,zuoye,char,flag,chazhao,yuan 来源: https://blog.csdn.net/TommY_YT/article/details/121513324