/*Write a Lex program that finds the length of the longest word (defined as a contiguous
string of upper and lower case letters) in the input.*/
%{ #include<stdio.h>
int k=0;
%}
%%
[a-zA-Z]+ {
if(yyleng>k)
{ k= yyleng;
}
}
%%
int main(int argc[],char **argv[])
{
yyin=fopen("abc.txt","r");
yylex();
printf("largest: %d",k);
printf("\n");
return 0;
}
//file abc.txt
|
Lex program to find the length of the longest word |
//Output of the above program
|
Lex program to find the length of the longest word
|
Checkout this video on Lex Program to Find the Length of the longest word.
how can I print the word instead of the length of the longest word ?
ReplyDeleteThank you!
ReplyDelete