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 ?

Recommended Answers

All 4 Replies

EOF isn't a character from the stream.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.