Question

Here's Exercise 5-11: Modify the program entab and detab (written as exercises in Chapter 1) to accept a list of tab stops as arguments. Use the default tab settings if there are no arguments.

entab is described as

Replace strings of blanks by minimum # of tabs/blanks to achieve same spacing. A tab should be given preference to let the array of chars store the "tab" as one index rather than multiple spaces.

What is a "tab stop" exactly and how can we accept a list of whatever the tab stops are? I'm confused.

Was it helpful?

Solution

When you hit tab, you travel to the next tab stop. For example, many text editors have the tab stops at all multiples of 8 (8, 16, 24, 32, 40, etc) so if you are in column (say) 11 and hit tab you go to column 16. If you're in column 14 and hit tab you also go to column 16. So a tab is not always worth a fixed amount of spaces, but however many are needed to go to the next tab stop.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top