Write a lex program to count the number of characters, words, spaces, end of lines in a given input file.
Answers
Answered by
0
Lex 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.
Let’s the how to count the number of lines, spaces and tabs using Lex.
Example:
Input:
Geeks for Geeks
gfg gfg
Output:
No. of lines=2
No. of spaces=3
No. of tabs=1
No. of other characters=19
Input:
Hello
How are you?
Output:
No. of lines=2
No. of spaces=4
No. of tabs=1
No. of other characters=15
Similar questions
Science,
6 months ago
Hindi,
6 months ago
Computer Science,
1 year ago
English,
1 year ago
Math,
1 year ago