Count the Vowels - Lex Program

Program:

// lex file: vw.l

%{
int count=0;
%}

%%

[aeiouAEIOU] {count++;ECHO;}

%%
main()
{
    yylex();
    printf("\nNumber of vowels= %d\n",count);
    return 0;
}

Output:

nn@linuxmint ~ $ lex vw.l
nn@linuxmint ~ $ gcc lex.yy.c -ll
nn@linuxmint ~ $ ./a.out<vw.txt
www.2k8618.blogspot.com
www.2k8cs.tk
www.google.com
www.gmail.com


Number of vowels= 10
nn@linuxmint ~ $

2 comments:

Related Posts Plugin for WordPress, Blogger...