K& R练习

K& R练习

问题描述:

Hi Group,

不是在寻找答案,而是更多的解释。在你有时间做这些令人兴奋的日子的时候回想起来,我可以问这个。


练习1-22要求程序 ;折"在第n列......等等之前,将长输入线分为2或

更短的线路。现在,网上和C中有大量的b / b
答案簿,其中包括一个

函数,用于将标签扩展为空白(取决于标签的位置与下一个制表位相关的
)。我一直在努力理解

为什么会这样做....为什么不单独留下标签。


甚至不确定我是否应该问这个,但无论如何.....

Tks

Hi Group,
Not looking for an answer, but more of an explanation. Thinking back
to those heady days when you had the time to do them, may I ask this.

Exercise 1-22 asks for a program to "fold" long input lines into 2 or
more shorter lines before the nth column... etc etc. Now, there are
numerous anwers on the web and in the "C answer book", which includes a
function to expand the tabs to blanks ( depending upon where the tab is
in relationship to the next tab-stop). I have been trying to understand
why one would do this....why not just leave the tabs alone.

Not even sure if I should have asked this, but anyway.....
Tks

2006年4月12日13: 18:44 -0700,mdh < MD ** @ comcast.net>写道:
On 12 Apr 2006 13:18:44 -0700, "mdh" <md**@comcast.net> wrote:
不寻找答案,但更多的解释。
...
功能将标签扩展到空白(取决于标签的位置>与下一个制表符的关系)。我一直在努力理解
为什么会这样做....为什么不单独留下标签。
Not looking for an answer, but more of an explanation.
...
function to expand the tabs to blanks ( depending upon where the tab is
in relationship to the next tab-stop). I have been trying to understand
why one would do this....why not just leave the tabs alone.




< off-topic>

简单:


(a)有些设备(打印机)不处理标签 - 他们可能会忽略

,或只打印在现代计算机/操作系统中,

打印机驱动程序将自动执行选项卡扩展,但对于

其他设备,您需要将其作为单独的步骤执行。


(b)我在代码中使用4列制表位。我的一些同事使用3

或8.(是的,我们应该有编码标准,但这是一个单独的故事)代码在某人身上仔细而精美地格式化's
屏幕,当有人在他/她的编辑器中使用不同的

默认设置查看它时看起来很糟糕。除非您使用空格而不是

标签。

< / off-topic>



<off-topic>
Simple:

(a) Some devices (printers) do not process tabs - They may ignore
them, or print only one space, etc. In a modern computer/OS the
printer driver will perform the tab expansion automatically, but for
other devices you need to do it as a separate step.

(b) I use 4 column tab stops in my code. Some of my colleagues use 3
or 8. (Yes, we should have coding standards for that, but that is a
separate story) Code carefully and beautifully formatted in somebody''s
screen, looks terrible when somebody looks at it with different
default settings in his/her editor. Unless you use spaces instead of
tabs.
</off-topic>




Roberto Waltman写道:

Roberto Waltman wrote:

简单:




< OT>


谢谢Roberto ......是的......我意识到文字有点老......但是它确实是回到主人身上的一种刺激。


感谢您的解释。


< OT>



<OT>

thank you Roberto...yes...I realize that the text is a bit old...but it
sure is a thrill to go back to the masters.

Thanks for that explantation.

<OT>


mdh写道:
不是寻找答案,而是更多的解释。回想那些你有时间做这些令人兴奋的日子,我可以问这个。

练习1-22要求程序折叠。在第n列之前将长输入线分成2或更短的线......等等现在,在网上和C答案簿中有许多答案,其中包括
函数将选项卡扩展为空白(取决于选项卡与下一个制表符相关的位置)。我一直在努力理解
为什么会这样做....为什么不单独留下标签。
Not looking for an answer, but more of an explanation. Thinking back
to those heady days when you had the time to do them, may I ask this.

Exercise 1-22 asks for a program to "fold" long input lines into 2 or
more shorter lines before the nth column... etc etc. Now, there are
numerous anwers on the web and in the "C answer book", which includes a
function to expand the tabs to blanks ( depending upon where the tab is
in relationship to the next tab-stop). I have been trying to understand
why one would do this....why not just leave the tabs alone.




在某些时候你会需要将标签转换为空格才能显示它们。这可能是终端或打印机的固件,

终端仿真器窗口的代码,或者

编辑器的显示功能。例如,以下来自NetBSD内核的摘录

终端处理代码将输出转换为空格

到一个无法自行处理标签的设备:


if(c ==''\'''&&

ISSET(oflag,OXTABS)&&!ISSET( tp-> t_lflag,EXTPROC)){

c = 8 - (tp-> t_column& 7);

notout = b_to_q("",c ,& tp-> t_outq);


-

Diomidis Spinellis

代码质量:开源视角( Addison-Wesley 2006)
http://www.spinellis.gr/codequality