Contact Learn C
Copy Program Share Program

Program 307: Display Occurrence of Word in the given String using Library Functions

Program 307: Display Occurrence of Word in the given String using Library Functions
 
#include<stdio.h>
#include<string.h>
main()
{
 int i,len,sublen,count=0;
 char str[100],substr[20],tempstr[20];
 printf("Enter String\n");
 gets(str);
 printf("Enter substring to find Occurances\n");
 gets(substr);
 len=strlen(str);
 sublen=strlen(substr);
 if(len>=sublen)
 {
  for(i=0;i<len;i++)
  {
   strncpy(tempstr,str+i,sublen);
   tempstr[sublen]='\0';
   if(strcmp(substr,tempstr)==0)
       count++;
  }
  printf("Given Substring Occured %d times\n",count);
 }
 else
 {
  printf("Entered SubString is More then given String\n");
 }
    
}

Explanation:

//Coming Soon...

Output:
Display Occurrence of Word in the given String using Library Functions

Display Occurrence of Word in the given String using Library Functions

Download App and Learn when ever you want

Get it on PlayStore
Get it on Amazon App Store
Get it on Aptoide