//Lex Program to Count the Number of Lines and Characters in the Input File
%{ #include<studio.h>
int n_char=0;
int n_lines=0;
%}
%%
\n {++n_lines, ++n_char;}
. ++n_char;
%%
int main(int argc[],char *argv[])
{
yyin=fopen("abc.txt", "r");
yylex();
printf("n# of characters: %d",n_char);
printf("\n");
printf("n# of lines: %d",n_lines);
printf("\n");
return 0;
}
// file abc.txt
|
Lex Program to Count the Number of Lines and Characters in the Input File |
// Output of the above program
|
Lex Program to Count the Number of Lines and Characters in the Input File |
Checkout this video on Lex Program to Count the Number of Lines and Characters.
how can i Print all words that are preceded by a or A. e.g. a car, A girl ?
ReplyDeleteand it must read it from file
and print it in one time