Lex Program to count the number of words in a given string.

Lex Program to count the number of words in a given string.
Thumnail Lex Peogram

Source Code:
%{
#include<stdio.h>
#include<string.h>
int word=0;
%}

%%

[\n] {printf("Total Number of Words: %d\n",word); word=0; printf("\nEnter the string: ");}

([a-zA-Z0-9])* {word++;}
%%

int yywrap(void){}

int main()
{
printf("\nEnter the string: ");
yylex();
return 0;
}
Output:
Output for Count the number of words in a given string.

For any query, please comment below.
SUBSCRIBE

Post a Comment

0 Comments