Count Sub String From Given String – C Program

Count Sub String From Given String – C Program

Write a C Program to find how many times sub string from given main string.


int main()

 int i,j,count=0;
 char firststr[100],substr[10];

 printf("Please, Enter the main string = ");

 printf("\nPlease, Enter the sub string = ");

 for(i=0; firststr[i]!='\0'; i++)
     for(j=0; firststr[i]==substr[j] && substr[j]!='\0'; i++,j++);

 printf("The String count = %d",count);

 return 0;

The find sub string c program output is:

Please, Enter the main string = This is a my pen.
Please, Enter the sub string = is

The String count = 2


Leave a Reply

Your email address will not be published. Required fields are marked *