Wednesday, September 2, 2020

Write a Lex program to count number of vowels and consonants in a given input string.

Step 1 :- lex filename.l or lex filename.lex depending on the extension file is saved with
Step 2 :-  gcc lex.yy.c
Step 3 :- ./a.out

cv.l


%{ int vowel=0; int const =0; %} %% [aeiouAEIOU] {vowel++;} [a-zA-Z] {const++;} %% int yywrap(){} int main() { printf("Enter the string of Vowels and Consonents ::"); yylex(); printf("Number of vowels are : %d\n", vowel); printf("Number of consonants are : %d\n", const); return 0; }



OUTPUT



sunny@sunny-PC:~/Desktop$ flex cv.l sunny@sunny-PC:~/Desktop$ gcc lex.yy.c sunny@sunny-PC:~/Desktop$ ./a.out Enter the string of Vowels and Consonents :: Peace begins with a smile
press ctrl+d
Number of vowels are: 9 Number of consonants are: 12








No comments:

Post a Comment

Please do not any spam link in Comment Box