Bug 14695

Summary: no example on printf precision --- manual subsection "12.12.6 Other Output Conversions"
Product: glibc Reporter: R N Alx <lascania>
Component: manualAssignee: Not yet assigned to anyone <unassigned>
Status: NEW ---    
Severity: enhancement CC: aj, ldv, mtk.manpages, roland
Priority: P2 Flags: fweimer: security-
Version: unspecified   
Target Milestone: ---   
URL: http://www.gnu.org/software/libc/manual/html_node/Other-Output-Conversions.html#Other-Output-Conversions
Host: Target:
Build: Last reconfirmed:
Attachments: .GIF picture of the manual page with wrong printf() example
.GIF picture with correct output conversion arguments printf() example

Description R N Alx 2012-10-10 09:38:44 UTC
Created attachment 6678 [details]
.GIF picture of the manual page with wrong printf() example

glibc manual chapter "12. I/O on Streams"
section "12.12 Formatted Output"
subsection "12.12.6 Other Output Conversions" contains the following example line:
"printf ("%3s%-6s", "no", "where");"

this example is incorrect because there are two missing dots that are used to specify the precision of the output, how may characters printf() outputs.

The correct version is:
"printf ("%.3s%-.6s", "no", "where");"

observe the dot inside %.3s and the second dot inside %-.6s !



Check the attached .gif image for better clarification !
Comment 1 Andreas Schwab 2012-10-10 10:00:45 UTC
printf ("%.3s%-.6s", "no", "where") does not produce " nowhere ".
Comment 2 R N Alx 2012-10-10 10:28:12 UTC
Mr Schwab,

This example code, is not my own, not-my-own example !
printf ("%3s%-6s", "no", "where")

this example is writen in the manual, it is writen wrong inside the online manual.

I filled this bug because I want the online manual subsection "12.12.6 Other Output Conversions" to be changed because of two reasons:

1. reason one

there are missing two dots, %3.s and %-.6s

2. reason two

printf ("%.3s%-.6s", "no", "where") does YES YES YES produce " nowhere ".
but not because of the output conversion arguments .3 and -.6, but because these two strings are only two characters and five characters long, thus the output conversion arguments .3 and -.6 have no influence

but if the online manual is changed to:
printf ("%.3s%-.6s", "noOoO", "whereEeEeEeE")
the result will be " noOwhereE "

which is what the online manual is trying to explain how printf() is using output conversion arguments to cut strings


CHECK THE .GIF IMAGE
http://sourceware.org/bugzilla/attachment.cgi?id=6678

CHECK THE ONLINE MANUAL
http://www.gnu.org/software/libc/manual/html_node/Other-Output-Conversions.html#Other-Output-Conversions

Thanx
Comment 3 Andreas Schwab 2012-10-10 10:42:03 UTC
printf ("%.3s%-.6s", "no", "where") does not produce " nowhere ", neither does printf ("%.3s%-.6s", "noOoO", "whereEeEeEeE") produce " noOwhereE ".  You need a field width bigger than the precision to get any padding.
Comment 4 R N Alx 2012-10-10 10:57:31 UTC
Created attachment 6679 [details]
.GIF picture with correct output conversion arguments printf() example
Comment 5 R N Alx 2012-10-10 10:59:57 UTC
Sir,

I'm sorry but you are mistaken.

Please see the image, to see confirmation.
http://sourceware.org/bugzilla/attachment.cgi?id=6679

Please modify the online manual to contain valid information !!!
Comment 6 Andreas Jaeger 2012-10-10 11:06:32 UTC
Just a question: Shouldn't the manual say "field width" instead of precision?

This is an example of a field of with 3:
printf ("%3s",...)
Comment 7 R N Alx 2012-10-10 11:15:39 UTC
(In reply to comment #6)
> Just a question: Shouldn't the manual say "field width" instead of precision?
> 
> This is an example of a field of with 3:
> printf ("%3s",...)

Your example is wrong, because you must put a dot before three, .3, if you want to printf() only the first three3 characters of a string !

The manual should say something like, "to output less than the width of a string use the precision option .n to output only first n characters from a string".

Regarding numbers, the manual should continue use precision.
Comment 8 Andreas Schwab 2012-10-10 11:58:57 UTC
This example has nothing to do with field width or precision, it is about alignment (which is useless without a field width).
Comment 9 R N Alx 2012-10-10 12:15:26 UTC
Mr Schwab

You said,
printf ("%.3s%-.6s", "no", "where") does not produce " nowhere "

You said,
printf ("%.3s%-.6s", "noOoO", "whereEeEeEeE") does not produce " noOwhereE "

THEY BOTH PRODUCE, " nowhere " RESPECTIVELY " noOwhereE "



Are you able too see pictures on your computer, or are you still using an old text-screen terminal ?



My bug is about
R N Alx 2012-10-10 10:28:12 UTC
http://sourceware.org/bugzilla/show_bug.cgi?id=14695#c2



If you do not understand, please let other people have a look at the images, and decide on this subject !

Do no longer stamp my bug as RESOLVED INVALID !

Thank You Sir !
Comment 10 Andreas Schwab 2012-10-10 12:33:27 UTC
printf ("%.3s%-.6s", "no", "where") produces "nowhere" and printf ("%.3s%-.6s", "noOoO", "whereEeEeEeE") produces "noOwhereE".
Comment 11 R N Alx 2012-10-11 11:31:08 UTC
COMPARE
http://sourceware.org/bugzilla/show_bug.cgi?id=14695#c3
http://sourceware.org/bugzilla/show_bug.cgi?id=14695#c10

dude Schwab, just stay away ! keep distance, let somebody else look at the issue, not you !

take a walk in nature, clean your mind !

STAY AWAY !!!!!!!!!
Comment 12 Andreas Schwab 2012-10-11 11:53:17 UTC
Stop reopening.  Nothing what you wrote is true.
Comment 13 Andreas Jaeger 2012-10-11 13:18:07 UTC
R NH Alx, we resolve conflicts in a friendly manner. Stop insulting Andreas Schwab.

It's fine to disagree on a technical level - but then you have to accept that Andreas is an expert in this area and disagrees with you.
Comment 14 R N Alx 2012-10-11 14:56:46 UTC
I do not care what flavour of expert is Andreas Schwab.

My physics teacher always tells me that the laws of physics are based only on experiments and nobody with great authority can impose a law only because he has greater authority !

In comment #3 and in comment #10, Andreas Schwab, contradicts himself, this makes me believe that he has limited knowledge on the subject.

Question:
Can you folks view .GIF images on your computer screens ?
Comment 15 R N Alx 2012-10-11 15:03:44 UTC
I want to output only 5characters from a 10character string

char str[] = "0123456789"

Which printf() call will do that job ?

I. printf("%5s", str)

or II. printf("%.5s", str)

Now lets see how big experts you are.
Comment 16 Andreas Schwab 2012-10-11 16:14:42 UTC
This is not the point of the example.  Read comment 8 again.
Comment 17 Dmitry V. Levin 2012-10-11 16:51:13 UTC
(In reply to comment #8)
> This example has nothing to do with field width or precision, it is about
> alignment (which is useless without a field width).

The reporter seems to be confused by the fact that this example demonstrates alignment while the text right before it talks about precision and there is no example on precision.
Comment 18 Andreas Schwab 2012-10-11 17:01:44 UTC
The last sentence before the example explicitly talks about the - flag.
Comment 19 R N Alx 2012-10-12 12:16:05 UTC
Alright !

Then take 2 minutes of your time and include an example on precision !
printf("%.5s", "0123456789")

produces:

‘01234’



Change the example about aligment from:
printf ("%3s%-6s", "no", "where");

change it to:
printf ("%10s(always)", "ON");
printf("\n");
printf ("%-10s(never)", "OFF");

produces:

‘        ON(always)’
newline
‘OFF       (never)’



And now you may stamp the bug as solved.