Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this first assignment there are only four formatting commands: ?width width : Each line following the command will be formatted such that there is

image text in transcribed

For this first assignment there are only four formatting commands:

?width width: Each line following the command will be formatted such that there is never more than width characters in each line. The original whitespace in the input text need not necessarily be preserved (i.e., single spaces are used to separate words in the output). If this command does not appear in the input file, then the input text is not transformed in the output.

?mrgn left: Each line following the command will be indented left spaces from

the left-hand margin. Note that this indentation must be included in the page width. If this command does not appear in the input file, then the value of leftis 0 (zero).

?fmt [off | on]: This is used to turn formatting on and off. If the commandappears with off, then all text below the command up to the next ?fmtcommand is output without being formatted. If the command appears withon, then all text below the command up to the next ?fmt command isoutput with as many words as will fill the given page width. (It may be that there is no ?fmt command following, in which case the choice of on or off is used for the remaining input text.)

There is some default behavior expected. (Some details from the previous bullet points are repeated below.)

If no ?width command appears, the default mode is ?fmt off. In this case all ?mrgn commands are ignored.

If a ?width command appears, the default mode is ?fmt on.

For this first assignment, there will only ever be one ?width or ?mrgn

command in an input file, and these will appear at the top of the file.

For this first assignment, you can assume that all test files will have page

widths that are much greater than left margins (e.g., there will not be a

combination such no as ?width 30 and ?mrgn 40).

There is no limit to the number of ?fmt commands that can appear within

an input file.

You are to write a C program that inputs lines of text files, reads formatting options contained within those text files, and then outputs the text where each line has the appropriate width, indenting, etc. as indicated by the formatting options. For example, here is one such file contained in the "test" subdirectory at /home/seng265/A1/test/ ("in04.txt"): ?width 30 While there fill are enough characters here to at least one line, there is plenty white space that needs to be eliminated from the original text file. This particular file contains one formatting option ("?width 30") which indicates that the following text must be formatted such that each line contains at most 30 characters. The formatting program also concatenates the lines of a paragraplh together in order to eliminate unnecessary white space. The resulting output (stored in "out04.txt") looks like this: While there are enough characters here to fill at least one line, there i:s plenty of white space that needs to be eliminated from the original text file

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Mary Z. Last

8th edition

1285427106, 978-1285427102

More Books

Students also viewed these Databases questions

Question

What problems face Russian automotive manufacturers?

Answered: 1 week ago