The Task

You should write a C program to implement the text handling task. After your C code is running, it should firstly ask the name of the text file being input from the keyboard manually. Then, it should open and read this text file. Finally, your C code should be able to analyse the text and output a meaningful answer to the screen and also to a file for submission with your C program.

Appendix 1 shows an example of the text file, which contains the following features:

  • The provided file contains typed text in the form of English words, punctuation marks and C keywords, which are separated by space.
  • The punctuation marks in the text file include the following four: comma (,), full stop (.), question mark (?), and exclamation mark (!).
  • The number of C keywords in the text file is more than 1 and less than 32.

At first, you should create a head file (***.h) to include C keywords and 4 punctuation marks given above, which will be then included in your C program. Your C program should read and analyse the text file, and then produce a correct output with the following format:

  • A line should be output when your program reads either one of punctuation marks listed above or one of C keywords from the text file. Note that the punctuation marks should go with the text being read already, e.g. Do these capabilities exist in most other languages?
  • A keyword should occupy one line itself, e.g. goto
  • When a keyword is followed by a punctuation mark (s), they should stay in one line, e.g. char,
  • The total number of lines should be counted and outputted as the last line with the prefix sentence "Total number of lines is: **".

Appendix 1

The following text is for you to type into a text file, namely "assignment1.txt".

C allows the programmer to write directly to memory unlike most of other programming languages. Key constructs in C such as pointers and arrays are designed to structure and manipulate memory in a machine-independent fashion. Thirty-two Keywords in C are also called as reserved words such as char int float goto and void. C gives control over the memory layout of data structures! C is a strongly typed language. This means that the variable type cannot be changed once it is declared. Here, the type of number variable is int. You cannot assign a floating-point (decimal) value 5.5 to this variable. Also, you cannot redefine the data type of the variable to double. By the way, to store the decimal values in C, you need to declare its type to either double or float. C provides a uniform interface when dealing with low-level code such as the part of the OS that controls a device. Do these capabilities exist in most other languages? Answer is no.
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.