"M.B" <> writes:
> Gladiator wrote:
[snip]
>> 2nd question is, we are using the EOF to compare it with a
>> value. Is it necessary to specify the EOF value before we use it in a
>> comparison?. One way what i could think is the EOF value may be the
>> maximum value that the variable can hold ( In this "Long"). But I am
>> not sure about it.
>>
> EOF is not any maximum defined by size of anything. it indicated that
> thatere are no more input available. it is defined in stdio . h and in
> unix it is ctrl+d.
> EOF is present at the end of all files (atleast in unix)
>
> if ctrl+d dont work in ur OS for EOF pls refer to OS manual for it
Both of you have misunderstood what EOF is all about.
Each file (including stdin) has an end-of-file indicator. This isn't
a character or a value, it's a condition; it indicates that the last
attempt to read from the file failed because it had reached the end of
the file.
EOF is a macro defined in <stdio.h>. It specifies the value that will
be returned by certain input functions, such as getchar(), on an
end-of-file or error condition. The value of EOF isn't specified by
the standard except that it's a negative integer (it's typically -1).
The getchar() function attempts to read a character. If it was
successful, it returns the value of that character, as an unsigned
char converted to int. (On a typical system, this will be a value in
the range 0..255.) If it failed, it returns the value EOF, which is
distinct from any valid character value.
A system will typically have some mechanism for the user to cause an
end-of-file condition when a program is reading from an interactive
device such as a keyboard. Under Unix, this is typically indicated by
typing control-D. Under MS-DOS, it's usually control-Z. Your program
won't see the control-D (4) or control-Z (26) value; it will instead
see the value EOF.
A disk file may or may not have some marker at the end of it to
indicate the end of the file. Under MS-DOS, a text file might have a
control-Z character at the end; under Unix, the system simply keeps
track of how big the file is.
--
Keith Thompson (The_Other_Keith)
kst- <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.