I need help understanding what Exercise 5-12 is asking for in the C Programming Language book

StackOverflow https://stackoverflow.com/questions/2649701

문제

K&R C Programming Language: pg. 105

Extend entab and detab to accept the shorthand

entab -m +n

to mean tab stops every n columns, starting at column m.

entab replaces a number of spaces with a tab character and detab does the opposite. The question I have concerns the tab stops and entab. I figure that for detab it's pretty easy to determine the number of spaces needed to reach the next tab stop, so no worries there. With entab, replacing spaces with tabs is slightly more difficult since I cannot for sure know how large the tab character goes to its own tab stop (unless there is a way to know for sure).

Am I even thinking about this thing properly?

도움이 되었습니까?

해결책

"tab stops every n columns, starting at column m" tells you how large each tab stop is, at least by my reading: it's just n. Only the first tab stop is different; that one is m.

다른 팁

entab needs to work out when runs of spaces reach a tabstop - then that run of spaces can be replaced by a tab character.

For example, the following line of text (the ruller is there for reference):

           1   1   2   2   2
1      8   2   6   0   4   8
-------+---+---+---+---+---+
          this     is a line

should look like the following after entab -8 +4:

\t  this \tis a line

(note that it might be reasonable for there to be two tab characters following 'this' in the line, since either a space or a tab would reach that particular tab stop).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top