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. When either a tab or a single blank would suffice to reach a tab stop, which should be given preference?
加粗部分是什么意思,请举例说明。
最佳答案
粗体问题基本上是要求您考虑制表符只能替换单个字符的特殊情况。那么是否值得/有必要用制表符替换该空格?
示例(带有制表位 - 由 ^
表示 - 每 3 个字符):
hello world
^ ^ ^ ^
两个单词之间有一个空格,可以用单个制表符(“hello\tworld”
)替换以实现相同的间距。你更换它吗?
同样:
hello world
^ ^ ^ ^ ^
两个单词之间有 4 个空格,可以用两个制表符 ("hello\t\tworld"
) 替换,或者用一个空格和一个制表符 ("hello\tworld"
),以实现相同的间距。你选择哪一个?
关于c - k&r 中的“entab”锻炼计划,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52198852/