Skip to content

Instantly share code, notes, and snippets.

@vnkdj5
Created May 2, 2019 16:15
Show Gist options
  • Save vnkdj5/10d24e3c9d6a2127c588e9edb5531ddf to your computer and use it in GitHub Desktop.
Save vnkdj5/10d24e3c9d6a2127c588e9edb5531ddf to your computer and use it in GitHub Desktop.
Word Count Program using Lex
vaibhav kumbhar
3434
PICT
%{
int nlines,nwords,nchars;
%}
%%
\n {
nchars++;nlines++;
}
[^ \n\t]+ {nwords++, nchars=nchars+yyleng;}
. {nchars++;}
%%
int yywrap(void)
{
return 1;
}
int main(int argc, char*argv[])
{
yyin=fopen(argv[1],"r");
yylex();
printf("Lines = %d\nChars=%d\nWords=%d",nlines,nchars,nwords);
return 0;
}
@chandrika9797
Copy link

chandrika9797 commented Aug 4, 2021

I'm not getting any output it's asking for data continuously

@vnkdj5
Copy link
Author

vnkdj5 commented Aug 4, 2021

I'm not getting any output it's asking for data continuously

Did you try the compilation steps as given on below link:
httpss://www.way2techin.com/2019/05/lex-program-to-count-words-lines-and.html

See the screenshot. It should work. You must be doing something differently. As we all executed same programs in our college days🤭.
If its not working , try figuring out the reason, afterall you are a programmer.🙂

Do hit the follow button on GitHub. If our programs helped you in some way :)

@chandrika9797
Copy link

yeah ok tqsm😊btw im not a programmer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment