K&R Exercises

Exercise 1-21: Entab

Write a program entab that replaces strings of blanks by the minimum number of tabs and blanks to achieve the same spacing. Use the same tab stops as for detab. When either a tab or a single blank would suffice to reach a tab stop, which should be given preference?

Put a tab stop every 8 columns, counting from column 0 at the start of each line. Use a blank when one blank reaches the tab stop. Copy tabs in the input unchanged.

Test Cases

· space→ tab↵ newline

Submissions

No submissions yet