LEX Program to count the number of vowels and consonants in a given string:
%{
int vow_count=0;
int const_count =0;
%}
%%
[aeiouAEIOU] {vow_count++;}
[a-zA-Z] {const_count++;}
%%
main()
{
printf("Enter the string of vowels and consonents:");
yylex();
printf("The number of vowels are: %d\n",vow);
printf("The number of consonants are: %d\n",cons);
return 0;
}
Output:
$$ lex kk.l
$$ gcc kk.c -ll
$$ ./a.out
Enter the string of vowels and consonents
My name is Khan
The number of vowels are: 4
The number of consonants are: 8
^D
$$
%{
int vow_count=0;
int const_count =0;
%}
%%
[aeiouAEIOU] {vow_count++;}
[a-zA-Z] {const_count++;}
%%
main()
{
printf("Enter the string of vowels and consonents:");
yylex();
printf("The number of vowels are: %d\n",vow);
printf("The number of consonants are: %d\n",cons);
return 0;
}
Output:
$$ lex kk.l
$$ gcc kk.c -ll
$$ ./a.out
Enter the string of vowels and consonents
My name is Khan
The number of vowels are: 4
The number of consonants are: 8
^D
$$
No comments:
Post a Comment