Lex program to find the Length of a String
Problem: Write a Lex program to find the Length of a String
Explanation:
FLEX (Fast Lexical Analyzer Generator) is a computer program that generates lexical analyzers and was written by Mike Lesk and Eric Schmidt. Lex reads an input stream specifying the lexical analyzer and outputs source code implementing the lexer in the C programming language.
Examples:
Input: geeksforgeeks Output: length of given string is : 13 Input: geeks Output: length of given string is : 5
Implementation:
/*lex program to find the length of a string*/ %{ #include<stdio.h> int length; %} /* Rules Section*/%% [a-z A-Z 0-9]+ {length=yyleng; } %% int main() { yylex(); printf("length of given string is : %d", length); return 0; } |
chevron_right
filter_none
Output:

Recommended Posts:
- C program to find the length of a string
- Lex program to find the length of the longest word
- C Program for focal length of a spherical mirror
- C Program for Number of jump required of given length to reach a point of form (d, 0) from origin in 2D plane
- C Program for Program to find area of a circle
- C program to check if a given string is Keyword or not
- Lex program to check whether given string is Palindrome or Not
- C Program to print all permutations of a given string
- Lex Program to accept string starting with vowel
- YACC program to recognize string with grammar { anbn | n≥0 }
- YAAC program to check whether given string is Palindrome or not
- LEX program to count the number of vowels and consonants in a given string
- TCP Client-Server Program to Check if a Given String is Palindrome
- C Program to find whether a no is power of two
- C Program to find transpose of a matrix
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



