Program:
%{
int lnno=0,wordno=0,charno=0;
%}
word [.* .*\t]
eol [\n]
%%
{word} {wordno++; charno+=yyleng;}
{eol} {charno++;lnno++;wordno++;}
. {charno++;}
%%
main()
{
yylex();
printf("Line number= %d\n",lnno);
printf("Word number= %d\n",wordno);
printf("Character number= %d\n",charno);
return 0;
}
Output:
nn@linuxmint ~ $ lex l6.l
nn@linuxmint ~ $ gcc lex.yy.c -lfl
nn@linuxmint ~ $ ./a.out <c1.c
Line number= 13
Word number= 43
Character number= 232
nn@linuxmint ~ $
( input file : c1.c
#include<stdio.h>
main ()
{
int i,n,fact=1;
printf("Enter the number: ");
scanf("%d",&n); //inputing the number
for(i=1;i<=n;i++) /* finding factorial */
{
fact = fact*i;
}
printf("Factorial=%d\n",fact);
}
)
%{
int lnno=0,wordno=0,charno=0;
%}
word [.* .*\t]
eol [\n]
%%
{word} {wordno++; charno+=yyleng;}
{eol} {charno++;lnno++;wordno++;}
. {charno++;}
%%
main()
{
yylex();
printf("Line number= %d\n",lnno);
printf("Word number= %d\n",wordno);
printf("Character number= %d\n",charno);
return 0;
}
Output:
nn@linuxmint ~ $ lex l6.l
nn@linuxmint ~ $ gcc lex.yy.c -lfl
nn@linuxmint ~ $ ./a.out <c1.c
Line number= 13
Word number= 43
Character number= 232
nn@linuxmint ~ $
( input file : c1.c
#include<stdio.h>
main ()
{
int i,n,fact=1;
printf("Enter the number: ");
scanf("%d",&n); //inputing the number
for(i=1;i<=n;i++) /* finding factorial */
{
fact = fact*i;
}
printf("Factorial=%d\n",fact);
}
)
plz explain the above program code.
ReplyDeletevery nice article word count tool
ReplyDeleteSuch a nice article ! I share this article with my friends. keep this type of blog in future.
ReplyDeleteWord Count Software
Well explained string operation .
ReplyDeletethere are good String program collection visit count the number of occurrences of a character in a string