In Kernighan and Ritchie (the C programming language):
'Write a program to print the value of EOF'
I wrote:
#include <stdio.h>
main(){
int c;
c = getchar();
if ((c = getchar()) == EOF)
putchar(c);
}
but it doesn't output anything Why?
putchar function prints a character.
But EOF is not a character and is used to indicate the End of a file. So the getchar returns a value which is distinguishable from the character sets so as to indicate there is no more input.
So printing EOF using putchar() wont print any values
printing it as integer
printf("%d",EOF);
gives result -1
try this:
#include <stdio.h>
int main(){
printf("EOF: %d\n", EOF);
}
EOF
is not a printable char as you expected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With