I need help understanding what exercise 5-12 in the C programming language book offers.

K&R C Programming Language: pg. 105

Extend entab and detab to accept shorthand

entab -m +n

means that the tab stops at each column n , starting from column m .

entab replaces the number of spaces with a tab character, while detab does the opposite. The question I have is regarding tab stops and entab . I believe it is pretty easy for detab to determine the number of spaces needed to reach the next tab, so no worries. Replacing spaces with tabs with entab a bit more complicated, since I cannot know exactly how big the tab character is going to its own tab (if there is no way to know for sure).

I even think about it right?

+4
source share
2 answers

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

+1
source

entab should work when white spaces reach the tabostop - then this run can be replaced with a tab character.

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

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

should look like entab -8 +4 :

 \t this \tis a line 

(note that it would be wise for the line to have two tabs following 'this', since either a space or a tab has reached this particular tab stop).

+1
source

Source: https://habr.com/ru/post/1307093/


All Articles