//Lex Program to Count the Number of Lines and Characters in the Input File
%{
#include<stdio.h>
int no_of_char=0;
int no_of_lines=0;
%}
%%
\n {++no_of_lines, ++no_of_char;}
. ++no_of_char;
%%
int main()
{
yyin=fopen("abc.txt", "r");
yylex();
printf("n0 of characters: %d",no_of_char);
printf("\n");
printf("n0 of lines: %d",no_of_lines);
printf("\n");
return 0;
}
//abc.txt file
output:
No comments:
Post a Comment