Sunday, 16 June 2019

Write a LEX program that reads program from input file and counts number of letters, words, lines from it. Resulting count should be written to output file.


              

               Code :

%{
#include<stdio.h>
int lines=0, words=0,letters=0;
%}
%%
\n {lines++; words++;}  
[\t ' '] {words++;}
[A-Za-z] {letters++;}
%%
main()
{
yyin=fopen("input.txt","r");
yyout=fopen("output.txt","w");
yylex();
fprintf(yyout,"\n\t%d lines",lines);
fprintf(yyout,"\n\t%d words",words);
fprintf(yyout,"\n\t%d letters",letters);
}
int yywrap()
{
return(1);
}

No comments:

Post a Comment

It's time To increase blogging capability. To have a chance to contribute in digital world. Any Interested People who want to make t...