#include <stdio.h>
#include <string.h>
int main(void)
{
int i=0,j=0,found=0,count=0,sw=0;
char str[50], sub[30];
printf("Enter string: ");
gets(str);
printf("Enter sub-string: ");
gets(sub);
while (str[i]!=EOF)
{
if (str[i]==sub[j])
{
i++;
j++;
sw=1;
if (j==strlen(sub))
{
j=0;
found=1;
count++;
}
}
else
{
if (sw==1)
{
j=0;
sw=0;
}
else
i++;
}
}
if (found==1)
printf("Found %d times\n",count);
else
{
if (found==0)
printf("Not found");
}
return 0;
}
/*
run:
Enter string: programming
Enter sub-string: ram
Found 1 times
*/