abhilashm86
February 19th, 2009, 07:31 PM
i did this simple lex program to count characters,lines,word.
problem error is word part is not counting??can anyone tell the modification to be done?
%{
#include<stdio.h>
int charc=0,wordc=0,linec=0;
%}
word [^\t\n]+
eol \n
%%
{word} {wordc++; charc +=yyleng;}
{eol} {charc++; linec++;}
. charc++;
%%
main()
{
yylex();
printf("line count=%d\nwprdcount=%d\ncharcount=%d\n",linec,wordc,charc);
}
also can i count spaces used?
problem error is word part is not counting??can anyone tell the modification to be done?
%{
#include<stdio.h>
int charc=0,wordc=0,linec=0;
%}
word [^\t\n]+
eol \n
%%
{word} {wordc++; charc +=yyleng;}
{eol} {charc++; linec++;}
. charc++;
%%
main()
{
yylex();
printf("line count=%d\nwprdcount=%d\ncharcount=%d\n",linec,wordc,charc);
}
also can i count spaces used?