only using C (not C++)
Implement a program that counts the words and prints theirfrequencies. In particular, the program extracts “words†from oneor more text files, from a pipe, or from the console, and prints tothe console the list of words found and their associatedfrequencies. Note that your project submission isrestricted to only using the following systemcalls: open(), close(), read(), write(), and lseek() for performingI/O. You are allowed to use other C library calls (e.g., malloc(),free()), however, all I/O is restricted to the Linux kernel’sdirect API support for I/O.
There are three ways the list of words is provided to yourprogram:
In a list of one or more files. The names of the files areprovided as arguments to your program (i.e., they are copied by theshell in the argv variable), and each file is atext file with lots of words.
The words are provided to stdin either bypiping or by user input.
An environment variable, WORD_FREAK, is setwith the name of the file containing the words.
We’ll focus on one of these ways, namely, getting the input froma file. Let’s assume the words are provided in one file, passed asan argument to your program (i.e., option 1). A sample text file(for this use any text file with thousands of words) is(not) provided. Given the constraint of using Linux API for I/O,complete the following:
Open the manual page for open() system call andadd to your code the header files required to useopen(), using the includepreprocessor statement.
Use the open() system call to open the filepassed to your program in argv[1] for reading.What flag should you pass to open(), to open thefile in read-only mode?
Open the manual page for read() system call andadd to your code the header files needed forread().
Use the read() system call to read thecharacters from the file. What parameters doesread() take, and what value does it return?Repeat, if necessary the call to read() until allcharacters are read from the input file.
Use printf() to output to the terminal the textjust read from the input file. Note that for the project you arenot allowed to use printf(). However, whiledebugging your code, it can be used to confirm the correct readingof the file contents.
Open the manual page for close() system calland determine which header file you should include in your code tocall close().
Use the close() system call to close thefile.