ugliness in scanf(3)

zben at umd5.UUCP zben at umd5.UUCP
Wed May 15 13:12:15 AEST 1985


In article <714 at oddjob.UUCP> matt at oddjob.UUCP (Matt Crawford) writes:
>In article <190 at mplvax.UUCP> cdl at mplvax.UUCP (Carl Lowenstein) writes:
>>In article <10496 at brl-tgr.ARPA> gwyn at Brl.ARPA (VLD/VMB) writes:
>>>
>>>If it ate the "failing" character, you could never see what it
>>>was.  I think the routine was designed on the assumption that
>>>the programmer would not be so stupid as to keep trying to
>>>scan a chunk of input over & over with the same failing format.
>>
>>This programmer is so stupid as to expect to find the behavior
>>of scanf documented in the manual.
>>
>THIS programmer is not too arrogant to open the manual before telling
>someone what's not in it:
>
>SCANF(3S)	    UNIX Programmer's Manual		SCANF(3S)
>
>     For example, .....
>
>	  int i; float x; char name[50];
>	  scanf("%2d%f%*d%[1234567890]", &i, &x, name);
>
>     with input
>
>	  56789	0123 56a72
>
>     will assign 56 to i, 789.0	to x, skip `0123', and place the
>     string `56\0' in name.  The next call to getchar will return
>     `a'.                    ------------------------------------
>     ----
>

The same documentation appears on our 2.9BSD system - I guess it is the same
on 4.xBSD - and yes, a reasonable person should be able, after scratching his
head for awhile, figure out what is happening.

How much time do you waste scratching your head?

The following mail arrived and I think it germane:

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

I get tired of people saying that UNIX & C are not documented.  There are
a few undocumented features of programs, but they are that way because they
might go away, and shouldn't be used (yet).  E.g., the VPATH variable in
make.  But all the system functions are documented *quite well*.  Take
the scanf manual page:

----
Scanf conversion terminates at EOF, at the end of the control string, or when
an input character conflicts with the control string.  In the latter case, the
offending character is left unread in the input stream.

Scanf returns the number of successfully matched and assigned input items;
this number can be zero in the event of an early conflict between an input
character and the control string.  If the input ends before the first conflict
or conversion, EOF is returned.
----

If that isn't *painfully obvious*, I don't know what is.  Maybe you're using
4.2BSD; if you do, I apologize.  That system is a total hack munged by grad
students and the documentation is even worse.  This excerpt comes from SVR2.
Since it is a production system, it has to be well-documented, and it is.

						Michael Baldwin
						AT&T Bell Labs

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

Now *this* is adequate documentation...

Re: "high priest" thing.  It's very easy to tell the most vicious form of
Polack joke, until you really become friends with a Pole.  It must similarly
be very easy to eliminate upon "high priests", until you are confronted with
one.  Maturity consists in large measure of doing what is right in preference
to doing what is easy.

Nuf said?

-- 
Ben Cranston  ...{seismo!umcp-cs,ihnp4!rlgvax}!cvl!umd5!zben  zben at umd2.ARPA



More information about the Comp.lang.c mailing list