Bug 20117

Summary: *printf manpage doesn't document %n
Product: Documentation Reporter: xaa <xaa>
Component: Books & ArticlesAssignee: freebsd-doc (Nobody) <doc>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Latest   
Hardware: Any   
OS: Any   

Description xaa 2000-07-23 09:40:00 UTC
	I tried to look up the actions of printf("%n"), but it wasn't
	in the manpage, only in the code

Fix: 

This is a lousy bit of description for what it does, but well,
	it's better than nothing.

(Before Format:)
Result type:
	An optional character that indicates the type of the value for
	use with format characters n, i, o, u and x. 'q' (or 'll') stands
	for a quad int, 'l' for a long int, 'h' for a short int. Int is
	default.

In the format characters:
n	Returns the amount of characters output so far, including
	formating actions. Requires a pointer value to write the value
	to. Beware: this changes your parameter!
Comment 1 Sheldon Hearn 2000-07-23 10:36:06 UTC
On Sun, 23 Jul 2000 10:31:25 +0200, xaa@dohd.org wrote:

> 	I tried to look up the actions of printf("%n"), but it wasn't
> 	in the manpage, only in the code

I would urge anyone looking into this to examine the C standard before
coming up with his own (possibly inferior) explanation.

Ciao,
Sheldon.
Comment 2 xaa 2000-07-23 17:55:00 UTC
The wise Sheldon Hearn produced the following lines:
> On Sun, 23 Jul 2000 10:31:25 +0200, xaa@dohd.org wrote:
> 
> > 	I tried to look up the actions of printf("%n"), but it wasn't
> > 	in the manpage, only in the code
> 
> I would urge anyone looking into this to examine the C standard before
> coming up with his own (possibly inferior) explanation.
> 
None around :-)
But well, I felt guilty not giving at least some attempt to fix it when
I PR'ed it
-- 
 Mark Huizer     -  xaa@timewasters.nl  -  xaa@dohd.cx  -  xaa@iae.nl

 If you're not in my dictionary, you're not in my universe.
 What would you like to be replaced with? (Clippy, the helpful
 paperclip)
Comment 3 jtaylor 2000-12-05 15:25:58 UTC
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

After some looking, I found this documentation from the GNU libc
manual. Would this be acceptable?

	The `%n' conversion is unlike any of the other output conversions.
    It uses an argument which must be a pointer to an `int', but
instead of
    printing anything it stores the number of characters printed so
far by
    this call at that location.  The `h' and `l' type modifiers are
    permitted to specify that the argument is of type `short int *'
or
    `long int *' instead of `int *', but no flags, field width, or
    precision are permitted.

       For example,

int nchar;
printf ("%d %s%n\n", 3, "bears", &nchar);

    prints:

3 bears

    and sets `nchar' to `7', because `3 bears' is seven characters


- -Jason

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.5.8 for non-commercial use <http://www.pgp.com>

iQA/AwUBOi0JBnGfX7CR8SmVEQLdhACfSerXAubqxVCEQR+XSrs5amYFEwoAoNiO
4xvs5xthFEgh/PQ+A9Dffkdp
=ZcL/
-----END PGP SIGNATURE-----
Comment 4 xaa 2000-12-05 15:30:08 UTC
The wise Jason M. Taylor produced the following lines:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> After some looking, I found this documentation from the GNU libc
> manual. Would this be acceptable?
> 
> 	The `%n' conversion is unlike any of the other output conversions.
>     It uses an argument which must be a pointer to an `int', but
> instead of
>     printing anything it stores the number of characters printed so
> far by
>     this call at that location.  The `h' and `l' type modifiers are
>     permitted to specify that the argument is of type `short int *'
> or
>     `long int *' instead of `int *', but no flags, field width, or
>     precision are permitted.
> 
>        For example,
> 
> int nchar;
> printf ("%d %s%n\n", 3, "bears", &nchar);
> 
>     prints:
> 
> 3 bears
> 
>     and sets `nchar' to `7', because `3 bears' is seven characters
> 
Fine with me, as long as something is in the man pages :-)

Mark
Comment 5 nik freebsd_committer freebsd_triage 2001-02-11 17:27:26 UTC
State Changed
From-To: open->closed

iMy -current system has this in printf(3) 

n       The number of characters written so far is stored into the inte- 
ger indicated by the ``int *'' (or variant) pointer argument.  No 
argument is converted. 

As far as I can see, it's been there forever. 

The text is not quite as verbose as some of the suggested replacements, 
but I'm wary of lifting text directly from GPLd man pages and putting it 
in our base system. 

If you think the text isn't clear enough, please suggest a replacement 
(ideally, as a patch :-) ), and PR it.  Thanks.