Computer Science, asked by Rubi7907, 1 year ago

Write a lex program to count number of vowels, number of lines and number of spaces in the text stored in a text file.

Answers

Answered by Abhinavj255
0
: Write a Lex program to count the number of vowels and consonants in a given string.


%{
#include<stdio.h>
int vowels=0;
int cons=0;
%}
%%
[aeiouAEIOU] {vowels++;}
[a-zA-Z] {cons++;}
%%
int yywrap()
{
return 1;
}
main()
{
printf(“Enter the string.. at end press ^d\n”);
yylex();
printf(“No of vowels=%d\nNo of consonants=%d\n”, vowels,cons);
}

How to Compile:
1.    Save the file with .l extention. E.g. vowels.l
2.    lex vowels.l
3.    gcc –o objfile lex.yy.c
4.    ./objfile

Similar questions