Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 7 May 1995 08:55:51 +0200 (MET DST)
From:      J Wunsch <j@uriah.heep.sax.de>
To:        freebsd-bugs@FreeBSD.org
Subject:   Re: bin/386: *s field width specification doesn't seem to work for printf
Message-ID:  <199505070655.IAA07462@uriah.heep.sax.de>
In-Reply-To: <no.id> from "j" at May 7, 95 05:24:08 am

next in thread | previous in thread | raw e-mail | index | archive | help
As j wrote (that's me, ain't it? :):


> "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.

I think i've fixed it now.  printf did a very lax syntax checking.
Digits and the asterisk have been treated equally in a fieldwidth/
precision string, resulting in "8*" being believed to be valid.

The paragraph

           o   If the leading character is a single or double quote, or not a
               digit, plus, or minus sign, the value is the ASCII code of the
               next character.

however explains why "foobarblatt" is considered to be the valid
number 102 (the ASCII value of "f").  It's weird, but intention.

Jordan: for your intention (to _limit_ the output width, if i
understood you right), you need to specify the precision, not the
field width:

	printf "%.8s"  foobarblatt

or

	printf "%.*s"  ${FIELD_LENGTH} foobarblatt

-- 
cheers, J"org

joerg_wunsch@uriah.heep.sax.de -- http://www.sax.de/~joerg/
Never trust an operating system you don't have sources for. ;-)



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