#include<stdio.h>
#include<string.h>
main()
{
	int i, j, m, n, index, count=0;
	char P[1000], S[1000];
	printf("Please enter the string P: ");
	gets(P);
	printf("Please enter the string S: ");
	gets(S);
	m = strlen(P);
	n = strlen(S);
	if (m<n) printf("String S is not a substring of string P");
	else
	{
		for (i=0;i<m-n;i++)
		{
			if (P[i]==S[0])
			{
				index=1;
				for (j=0;j<n-1;j++)
				if (P[i+j]!=S[j])
				{
					index=0;
				}
				if (index==1) count++;
				i+=n;
			}
		}
	}
	printf("S appears in P %d times",count);
}