# include<stdio.h>
# include <conio.h>
# include <string.h>
void main()
{
int noc=0,l;
FILE *fp;
char *str2,ch;
char*str1;
clrscr();
printf("Enter the String to be matched\n");
gets(str1);
l=strlen(str1);
fp=fopen("A.C","r");
while(1)
{
ch=fgetc(fp);
if(ch==EOF)
break;
else if(ch==' ')
{
fgets(str2,l+1,fp);
if((strcmp(str1,str2))==NULL)
noc++;
}
}
printf("NO of occurence is: %d",noc);
getch();
}
Run Code Online (Sandbox Code Playgroud)