#include <stdio.h>
#include <string.h>
int main()
{
int find(char str1[],char str2[])
{
int i,j;
int len1,len2;
int num=0;
len1=strlen(str1);
len2=strlen(str2);
for(i=0;i<len1;i++)
{
for(j=0;j<len2;j++)
{
if(str1[i+j]!=str2[j]) break;
}
if(j==len2)
num++;
}
return num;
}
char a[50];
char b[50];
int c=0;
printf("please import the string:");
gets(a);
printf("please import the substring:");
gets(b);
c=find(a,b);
printf("the number of occurences of substring is %d",c);
printf("\n");
return (0);
}
查找子串的数量
最新推荐文章于 2021-05-07 21:06:53 发布