-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
hugo27 wrote:
|
|>hugo27 wrote:
|>
|>>obrhy8 June 18, 2004
|>>
|>>Most compilers define EOF as -1. I'm just putting my toes
|>>in the water with a student's model named Miracle C. The
|>>.h documentation of this compiler does state that when
|>>scanf cannot fill any fields it returns EOF.
|>>I have run some tests on scanf and, so far, I've not found
|>>an EOF return.
|>>
|>>For example: If the programer formats scanf for an int or
|>>float type, and the user enters a single non-digit char or
|>>a char string, scanf writes nothing, fills no field, returns 0
|>>and exits to program. The keyboard buffer retains entire input.
|>>
|>>In this case one can test the scanf return for 0, then scanf
|>>the buffer into a charArray and printf charArray, to see what
|>>was left in buffer by 1st scanf.
|>>
|>>In no case did scanf return EOF.
|>>What condition or event then,
|>>would force scanf to return -1?
|>
|>Return Value
|>------------
|>
|>The number of items successfully matched and assigned. If input
|>ends, or if there is any input failure before the first item is
|>converted and assigned, `EOF' is returned. Note that literal
|>characters (including whitespace) in the format string which matched
|>input characters count as "converted items", so input failure
|>*after* such characters were read and matched will *not* cause `EOF'
|>to be returned.
|
|
|
|
| Obrhy8 june 19, 2004
|
|
|>For all: I just tested Miracle C and EOF IS -1.
In the "Miracle C" compiler, the EOF manifest constant is defined as -1.
However, -1 is not necessarily EOF. The standard only requires that the EOF
macro resolve to a negative integer constant; under a different compiler, EOF
could resolve to -127 or -8 or -65536.
|
|>L. Pitcher:
|>Perhaps there is some confusion between Keyboard input
|>and FILE I/O.
Nope. No confusion. To C, both are the same.
| EOF sure has a meaning in FILE I/O
|>but I mean here Keyboard buffer input.
Nope. end-of-file is a /condition/ that is recognized by the operating
environment and passed on to your program as the unique value EOF. It has
equal meaning in both an interactive and a file I/O mode, both in terms of the
operating environment (that is to say, it signals "no more data") and in terms
of the C programming language (that is to say, C informs your program that the
operating environment has, for whatever reason, determined that there is a "no
more data" condition on the file being read).
Under MSDOS, it is signalled when someone enters ^Z to signal that there is no
more keyboard input. Under Unix, the condition is signalled when someone
enteres the 'eof' char (usually ^D).
|>When the user keys in data and presses ENTER
|>scanf can read to the \n code. How is it possible
|>for scanf to read beyond \n?
EOF is the value returned by the stdio routines when the operating enviroment
tells them that there is no more data to read. If the I/O buffers have been
exhausted before the scanf() is called, then the scanf() invokes (through
implementation defined behaviour) a read of data from the operating
environment. If the operating environment returns more data, then that data is
parsed by scanf() and all is well. However, if the operating environment
returns a 'no more data' indicator, then the stdio support returns the EOF
value. /That's/ how scanf() can read beyond the \n.
|
|>B. Schwarz and J.
|>What constitutes such an error?
|>What does "input faliure" mean?
|>I have done a number of test on scanf and I find three broad
|>cases. First, scanf reads everything assigns field(s),
|>returns number. KB buffer MT
|>Second, scanf reads part of buffer, assigns field(s),
|>returns number. KB buffer retains some data.
|>Third, scanf reads nothing, writes nothing, returns 0.
|>KB buffer retains all input.
|
|
|>I have found NO case where scanf returns EOF (or -1)
|>ever, in anything like normal operation.
If you are using MSDOS, ^Z (that's <ctrl>Z), followed by the return key.
You'll get an EOF value passed to scanf() when it tries to parse this line.
- --
Lew Pitcher
Master Codewright & JOAT-in-training | GPG public key available on request
Registered Linux User #112576 (
http://counter.li.org/)
Slackware - Because I know what I'm doing.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Using GnuPG with Thunderbird -
http://enigmail.mozdev.org
iD8DBQFA1P9kagVFX4UWr64RAiM8AJ0QOloHGCp7Dzu+HZRU/wqOot/e5QCgmAnk
TkfqXVaJdtyIo4LA226ThkM=
=cZqx
-----END PGP SIGNATURE-----