Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 7 May 1995 14:45:47 +1000
From:      Bruce Evans <bde@zeta.org.au>
To:        freebsd-bugs@FreeBSD.org
Subject:   Re: bin/386: *s field width specification doesn't seem to work for printf
Message-ID:  <199505070445.OAA02207@godzilla.zeta.org.au>

next in thread | raw e-mail | index | archive | help
>> > 	Try this:  printf "%8*s" foobarblatt

>> You are missing the required int arg for the * and foobarblatt is being
>> used for this int.  foobarblatt is probably some rather very large int

Not quite.  It's a nonsense format.  The behaviour is undefined.  printf(1)
ends up calling printf(3) with printf("%8*s", "foobarblatt").

>"foobarblatt" ain't a valid int.  printf(1) misses an argument in that
>case.  It expected two args (for the * and for the s) and got only
>one.  The least one could expect is it loudly complains about this.

printf(1) doesn't seem to do any more error checking than printf(3).

>Furthermore, if you omit the asterisk, you'll be surprised that you
>can still see a very nice "foobarblatt" instead of the expected
>"foobarbl".  You can also replace the command by

>	printf "%*s" 8 foobarblatt

>to the same avail.

No, the 8 is the (minimum) field width.

	printf "%.*s" 8 foobarblatt

specifies the precision as 8 to truncate the string.

Bruce



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199505070445.OAA02207>