#include <stdio.h>
#include <string.h>
#define Num 1000
int main()
{
int i = 0,j = 0,k,count = 0,h = 0,c;
char str1[Num],str2[Num],str3[Num];
printf("Please input the first string,and enter as the end:\n");
while((c = getchar()) != EOF && c != '\n')
{
str1[i] = c;
i++;
}
printf("Please input the second string,and enter as the end:\n");
while((c = getchar()) != EOF && c != '\n')
{
str2[j] = c;
j++;
}
if(i < j)
{
printf("str1 has 0 str2");
}
else
{
for(k = 0;k < i - j + 1;k++)
{
for(h = 0;h < j;h++)
{
str3[h] = str1[k + h];
}
if(strcmp(str3,str2) == 0)
count++;
}
printf("str1 has %d str2s",count);
}
return 0;
}
转载于:https://www.cnblogs.com/batteryhp/p/5020484.html