Friday, April 12, 2019

lex program to count word “India” from file


%{
  #include<stdio.h>
  int count=0;
%}
%%
[iI][nN][Dd][iI][Aa] count++;
.
\n
%%
int main()
{
  FILE *fp;
  fp=fopen("4.txt","r");
  if(fp==NULL)
  {
       printf("Error");
  return 0;
  }
  yyin=fp;
  yylex();
  printf("India is in file %d times",count);
}

ScreenShot:


No comments:

Post a Comment