Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Exercise 1-20. Write a program detab that replaces tabs in the input with the proper number of blanks to space to the next tab stop. Assume a fixed set of tab stops, say every n columns. Should n be a variable or a symbolic parameter?

Exercise 1-21. 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?

could you paraphrase these for me. thanks

share|improve this question

closed as off-topic by MichaelT, BЈовић, Kilian Foth, Bart van Ingen Schenau, GlenH7 Aug 1 '13 at 18:10

  • This question does not appear to be about software development within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

Perhaps could you specifically write what you don't understand? The whole question is off-topic here though... –  Jonathan Khoo Mar 17 '11 at 5:36
This question appears to be off-topic because it is about the requirements of a specific homework problem rather than a more general problem in software development. –  MichaelT Aug 1 '13 at 1:28

2 Answers 2

Exercise 1-20:

Normally, tabs are four spaces long (or some constant number of spaces). However, sometimes tabs can be fewer spaces. This is done in order to align the text in the file into columns and four spaces would misalign the columns. You are asked to replace the tab characters with space characters to achieve the same effect.

Write a program called detab. This program must work as follows:

  • The input is a file, with some lines of text in it.
  • Each line in the file may have some tabs
  • If the line has tabs, remove the tab and in its place, insert some (the correct amount) spaces.

Exercise 1-21:

This is the exact opposite of Exercise 1-20. Here, you have a file with spaces instead of tabs and you have to replace the spaces with tabs. The obvious way to do this to replace each space with a tab. However, the question states that you should use as few tab characters as possible to achieve this.

Hope this helps

share|improve this answer

Alright, for both of these I'm setting some qualitative norms.

Tab Stop : point along a line of text where - when a tab is used - the cursor will move to.

Column : fixed width of line of text (say 80 "characters") : [chunks of an array or list]

When one indents on most newer text editors there are defined stopping positions so that all of the tab positions, regardless of text in-front of it, will start at the same position. ie.

|a _ _ _ |b _ _ _ |c

| Start | 1st Tab | 2nd Tab

|a b _ _ |_ _ _ _ |c

[the underscores delineating spaces] the 'c' should line up with itself on the next line if it were tabbed:

Detab should take the tabs and change the distance to the next tab point - underscores - to spaces.

Entab should take the spaces/blanks and change them into tabs.

Your program doesn't need to account for other values besides spaces and this tab value which you will have to define as a number of columns.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.