#include <stdio.h>
#include <string.h>
#define MAX_SIZE 1024
int main()
{
int i;
int k = 0;
int count = 0;
int len1 = 0;
int len2 = 0;
char str1[MAX_SIZE];
char str2[MAX_SIZE];
printf("please input the string1:\n" );
scanf("%s",str1);
printf("please input the string2:\n");
scanf("%s",str2);
len1 = strlen(str1);
len2 = strlen(str2);
for(i = 0; i < len1; i++)
{
while(k < len2 && str1[i] == str2[k])
{
k++;
i++;
}
if(k == len2)
{
count++;
i--;
}
k = 0;
}
printf("the number is %d:\n",count);
return 0;
}
输出一个字符串中含有所规定的字符子串的数量
最新推荐文章于 2023-11-04 21:05:09 发布