To write a LEX program to count no of vowels and consonants in a given string.
/* decleration section */
%{#inlcude<stdio.h>
int v_count=0;
int c_count=0;
%}
/* definition section */
%%
[aeiouAEIOU] {v_count++; }/*for vowels counting in the string*/
[a-zA-Z] {c_count++; }/* for consonants counting in the string*/
%%
/* main section */
void main(int argc[],char *argv[])
{
yylex();
printf("no of vowels in the string is:%d\n",v_count);
printf("no of consonants in the string is :%d\n",c_count);
}
Comments
Post a Comment