printf ("%d",EOF);

This gives me -1

scanf ("%d",&a);
printf ("%d",a)

where a is int (as EOF is an int), this gives me some junk value

printf ("%d",getch());

This gives me 26

I've always given the input as ctrl+z (that's right, na!)

What's the correct value of EOF ?

Edited by WaltP: Use the PREVIEW button so you can correct badly formatted posts

8 Years
Discussion Span
Last Post by Narue

Thanks !

Plz take time out to check if I have understood correctly

EOF is a value returned when the end of an input stream occurs. Its value in most systems is -1. In C, EOF is a macro defined as -1. Note that EOF is not some character returned from the input stream. In Unix, the end of input is indicated by ctrl+d (whose ascii value is 4) while in Windows, its Ctrl+Z (whose ascii value is 26). When receiving an input stream, if Ctrl+Z is sensed in Windows or Ctrl+D in Windows, Its interpreted as the end of input, and EOF (i.e. -1) is returned to the program. Both of them are also called EOT (End of transmission

character for their respective environments).


>Its value in most systems is -1.
The actual value is irrelevant.

>In C, EOF is a macro defined as -1.
EOF is defined as a negative constant with a type of int, nothing more.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.