#include
#include
void main()
{
int count_substr(char *str,char *sub_str);
char string[100];
char sub_str[100];
printf("input a string:\n");
scanf("%s",string);
printf("input the substring:\n");
scanf("%s",sub_str);
char *str1,*str2;
str1 = string;
str2 = sub_str;
printf("count = %d",count_substr(str1,str2));
}
int count_substr(char *str,char *sub_str)
{
int count = 0;
int i,j;
for(i=0;i{
for(j=0;j{
if(*(sub_str+j)!=*(str+i+j))
break;
}
if(j==strlen(sub_str))count++;
}
return count;
}