Lex program to Count Number of Vowels And Constants in a Given Input String.


Aim :- Write a Lex program to count number of vowels and constants in a given input string.


C Program Code :


%{
      int v=0,co=0,n=0;
%}
%%
      [aeiou] v++;
      [0-9] co++;
      n++;
%%
int main()
{
      FILE *f;
      char file[10];
      printf("Enter File Name : ");
      scanf("%s",file);
      f=fopen(file,"r");
      yyin=f;
      yylex();
      printf("\nNumber of Vowels : %d",v);
      printf("\nNumber of Constants : %d",co);
      return 0;
}
int yywrap()
{
      return 1;
}



Input :







Output :


Post a Comment

3 Comments