Tuesday, 3 December 2013

Count the nuber of Sentences and Words using Flex [ lex program part 9 ]

Program


       

%{
int a=0;
int b=0;
%}
word [a-z]+[ ]
sent [.?!]
%%
{sent} a++,b++;
{word} a++;
%%
void main()
{
printf("Enter the String \n");
yylex();
printf("number of words %d \n",a);
printf("number of sentence %d \n",b);

}
        
    

Output

   

lex even.l
cc lex.yy.c -lfl
./a.out
        
    
 then press CTRL+d

0 Comments:

Post a Comment

Facebook Twitter Delicious Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | coupon codes