本文介绍了需要解释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我在假期再次写这个教程的东西我遇到了

这个问题:


宽度 printf中的字段是最小宽度。 Printf不会截断

字段。例如:

#include< stdio.h>

int main(无效)

{

printf ("%5s%03d \ n"," 1234567890",12345);

}


将打印

1234567890 12345

而不是

12345 123

如预期的那样。


---- ---------------


好​​的,但我怎么能解释这个东西?有什么理由吗?

不,与之前的错误兼容不是解释

至少对我来说,而不是初学者。


我能在这说什么?


谢谢

Hi

I am writing this tutorial stuff again in the holidays and I came across
this problem:

The "width" field in printf is a minimum width. Printf will not truncate
a field. for instance:
#include <stdio.h>
int main(void)
{
printf("%5s %03d\n","1234567890",12345);
}

will print
1234567890 12345
and NOT
12345 123
as expected.

-------------------

OK, but how can I EXPLAIN this stuff? Is there any reason?
And no, "compatibility with previous bugs" is NOT an explanation
at least for me, and not for a beginner.

What could I say here?

Thanks

推荐答案



我建议你需要认真修复你的前任。

I suggest serious repair of your expecter is needed.



漂亮的,排队的输出并不像获得值

那样重要。这并不像打卡上的输出那样

一切都必须从正确的列开始。如果你的薪水中有其中一个值,那么你想要的是什么?

Pretty, lined-up output is not as important as getting the value
right. It''s not like the output is going on punch cards where
everything has to start in the right column. If one of those values
was on your paycheck, which would YOU want?



您是否想提及与

FORTRAN的故意IN兼容性,其中填满了不符合*行的字段* 's?

Would you like to mention a deliberate INcompatability with
FORTRAN, which filled up fields that didn''t fit with a row of *''s?



如果要打印不同的数字,请计算不同的

数。例如,n / 100或n%1000可能是您想要打印的数字



If you want to print a different number, calculate a different
number. For example, n/100 or n%1000 might be the number you want
to print.





我建议你需要认真修复你的前任。



I suggest serious repair of your expecter is needed.




漂亮的,排队的输出并不像获得值

那样重要。这并不像打卡上的输出那样

一切都必须从正确的列开始。如果你的薪水中有其中一个值,你想要的是什么?



Pretty, lined-up output is not as important as getting the value
right. It''s not like the output is going on punch cards where
everything has to start in the right column. If one of those values
was on your paycheck, which would YOU want?



问题是不可能削减产量一个%s

来避免缓冲oevrflow。这导致了软件中的严重问题,人们忘记了这种错误。

The problem is that it is impossible to cut the output of a %s
to avoid a buffer oevrflow. This has led to serious problems in software
where people forgot this misfeature.




您是否愿意提及与
FORTRAN的故意兼容性,其填补了不适合的字段一行*'s?



Would you like to mention a deliberate INcompatability with
FORTRAN, which filled up fields that didn''t fit with a row of *''s?



这本来是一个更好的方法。


好​​的,没有解释那么?


因为你所说的实际上是:


就像那样,吞下它或使用Fortran。


我的意思是我想*解释*的东西,为这样的语言决定提供一些

*原因*。


谢谢你的回答。

That would have been a much better approach.

OK, no explanation then?

Because all you say is actually:

"It is like that, Swallow it or use Fortran".

I mean I would like to *explain* stuff, offer some
*reason* for language decisions like this.

Thanks for your answer.




字段宽度是一个宽度,可以正确,整齐地显示数据

。如果数据不适合现场,那么你可能想要牺牲而不是正确,这可能是整洁。


精度略有提高更难解释,因为它确实为每种类型做了不同的事情,但一般的想法是显示多少数据来显示。


因此精度决定了值的格式,字段

width指定了它的布局方式,但是没有超越

精度。


- Richard


-

应考虑到需要多少人一些字母表中包含32个字符

" - 1963年的X3.4。

The field width is intended to be a width that will display the data
correctly and neatly. If the data doesn''t fit in the field, it''s
probably neatness you want to sacrifice rather than correctness.

The precision is slightly harder to explain, because it does different
things for each type, but the general idea is how much of the data to
display.

So the precision determines how the value is formatted, and the field
width specifies how it should be laid out, but doesn''t override the
precision.

-- Richard

--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.


这篇关于需要解释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 06:06