#define MAXS 256
void main()
{
char s[MAXS],t[MAXS];
char *p;
int count=0;
// Accept string
printf("Enter some string:\n");
gets(s);
//Accept substring
printf("Enter search pattern:\n");
gets(t);
//Move pointer to the begining of string
p=s-1;
// Check for the substring and increment its occurence
while((p=strstr(p+1,t))!=NULL)
{
count++;
}
printf("Number of occurences=%d",count);
}
0 comments: