Problem C - Fmt
The unix fmt program reads lines of text, combining and breaking lines
so as to create an output file with lines as close to without exceeding
72 characters long as possible. The rules for combining and breaking
lines are as follows.
-
A new line may be started anywhere there is a space in the input.
If a new line is started, there will be no trailing blanks at the
end of the previous line or at the beginning of the new line.
-
A line break in the input may be eliminated in the output, provided
it is not followed by a space or another line break. If a line
break is eliminated, it is replaced by a space.
-
Spaces never appear at the end of a line.
-
If a sequence of characters longer than 72 characters appears without
a space or line break, it appears by itself on a line.
Sample Input
Unix fmt
The unix fmt program reads lines of text, combining and breaking lines so as to
create an
output file with lines as close to without exceeding
72 characters long as possible. The rules for combining and breaking
lines are as follows.
1. A new line may be started anywhere there is a space in the input.
If a new line is started, there will be no trailing blanks at the
end of the previous line or at the beginning of the new line.
2. A line break in the input may be eliminated in the output, provided
it is not followed by a space or another line break. If a line
break is eliminated, it is replaced by a space.
Output for Sample Input
Unix fmt
The unix fmt program reads lines of text, combining and breaking lines
so as to create an output file with lines as close to without exceeding
72 characters long as possible. The rules for combining and breaking
lines are as follows.
1. A new line may be started anywhere there is a space in the
input. If a new line is started, there will be no trailing blanks at
the end of the previous line or at the beginning of the new line.
2. A line break in the input may be eliminated in the output,
provided it is not followed by a space or another line break. If a
line break is eliminated, it is replaced by a space.