Problem: Write a Lex program to search a word in a file.
FLEX (Fast Lexical Analyzer Generator) is a tool/computer program for generating lexical analyzers (scanners or lexers) written by Vern Paxson in C around 1987. Lex reads an input stream specifying the lexical analyzer and outputs source code implementing the lexer in the C programming language. The function yylex() is the main flex function which runs the Rule Section.
Input: welcome to geeksforgeeks Output: welcome FOUND for NOT FOUND geeksforgeeks FOUND
To search a word, I have stored words in file named “input.txt” and used lex to receive words from keyboard. On receiving each word, I check it with the words in the file. If the word is found, the program prints “FOUND” else “NOT FOUND”.
Input File: input.txt (Input File used in this program)
Below is the implementation of program:
- Lex program to count the frequency of the given word in a file
- Lex code to replace a word with another word in a file
- Lex program to copy the content of one file to another file
- C Program for Anagram Substring Search (Or Search for all permutations)
- Lex program to find the length of the longest word
- C program for file Transfer using UDP
- C Program to find size of a File
- LEX program to add line numbers to a given file
- C Program for Lower Case to Uppercase and vice-versa in a file
- C/C++ Program for Linear Search
- Lex program to take input from file and remove multiple spaces, lines and tabs
- Lex Program to print the total characters, white spaces, tabs in the given input file
- C Program for Binary Search (Recursive and Iterative)
- Basics of File Handling in C
- File opening modes(r versus r+)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.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.