Possible scanf bug?
The Grey Wolf
greywolf at unisoft.UUCP
Wed Feb 6 08:32:57 AEST 1991
In article <RJOHNSON.91Jan31110927 at olorin.shell.com> rjohnson at shell.com (Roy Johnson) writes:
>In article <146 at thor.UUCP> scjones at thor.UUCP (Larry Jones) writes:
[ scanf not reading what the user wants, said to return zero ]
>Except that it would return 1, for number of variables assigned, not
>number of formats read.
>From BSD 4.3 UNIX, scanf(3S) manual page:
"The _s_c_a_n_f functions return the number of successfully
matched and assigned input items[*]. This can be used to decide how many
^^^^^^^^^^^^^^^^^^^^ [implies both]
input items were found. The constant EOF is returned upon end of input;
note that this is different from 0, which means that no conversion was
done; if conversion was intended, it was frustrated by an inappropriate
character in the input."
The Pyramid OSx (BSD) man page reads likewise.
[*] The SunOS 3.5 and 4.0.3 manuals and the Pyramid OSx (AT&T) man page read
similarly, but with the stipulation inserted here:
"...this number can be zero in the event of an early conflict between
an input character and the control string.
>
>--
>======= !{sun,psuvax1,bcm,rice,decwrl,cs.utexas.edu}!shell!rjohnson =======
>"If he exploded, all of Manhattan would be talking in high, squeaky voices
>for months!" "Cool." -- When I Was Short
>Roy Johnson, Shell Development Company
Of course, how it actually works in *practice* may vary from system to
system (depending upon how braindead your implementation of the stdio
functions is).
--
thought: I ain't so damb dumn! | Your brand new kernel just dump core on you
war: Invalid argument | And fsck can't find root inode 2
| Don't worry -- be happy...
...!{ucbvax,acad,uunet,amdahl,pyramid}!unisoft!greywolf
More information about the Comp.lang.c
mailing list