Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Need Code C 1 Requirements The program given in section 1.5.4 of Kernighan and Ritchie reads a text file from the standard inpat stream and
Need Code C
1 Requirements The program given in section 1.5.4 of Kernighan and Ritchie reads a text file from the standard inpat stream and outputs the number of characters, words, and lins of the inpat file. Your tnsk is to modify this progrum (or completely rewrite it) so that for each line of the inpat file, the characters in the line are echoed to the standard output strenm preceded by the line number (formatted to take at lenst 2 characters, right justified, surrounded with parentheses and followed by a space) and followed by the number of words in the line and the number of characters in the line enclosed in square bracbets and separated by a comma and a space After echoing the original file, output a blank line followed by three more lines with the following information: the number of lines, words, and characters (us in the original, just more verbowe); the line number of the line with the most words and the number of words on that line; the line number of the line with the most charweters and the number of characters on that line. If two or more lines tie for the same number of aords/charncters, regort the earlier line. Exactly match the formatting given in the example below. 1.1 Example For example, given an impat file containing: It is by will alone I set my mind in notion. It is by the juice of Sapho that thoughts acquire speed, the lips acquire stains, the atains becoue a warning. It is by will alone I set ay mind in notion. -- Mentat mantra from David Lynch's Dune novie Your program must output (1) It is by uill alone I set ny aind in mation. [11, 44] (2) It in by the juice of Sapho that thoughts acquire apeed, [11, 56] (3) the lips acquire stains, the staine become a uarning. [9,56] (4) It is by uill alone I set ny aind in mation. [11, 44] (5) -- Mentat antra fran David Lynch's Dune movie [8, 52] 5 lines, 50 words, 252 characters Line 1has the nost words with 11 Line 2 has the nost characters vith 56 1.2 Assumptions You may assume that the input contains only the standard ASCII printable characters (decimal codes 32 through 126) along with newline, ' n ', and tab, ' \t '. You may also assume that the input will end with a newline character. Hint: When a charscter, c, is read that is not EaF and not a newline, immedintely echo it to the stnndard output strenm with: printf ("4c,c)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started