I have a C program.
int main ()
{
if (getchar()!=EOF)
puts("Got a character");
else
puts("EOF");
}
What should I type into the stdin on the terminal to produce an EOF?
In Windows, Control+Z is the typical keyboard shortcut to mean "end of file", in Linux and Unix it's typically Control+D.
printf("EOF=%d\n", EOF);
, no need to get the value from getchar()
, just use the macro directly.
To determine what the value of EOF is on your platform you can always just print it:
printf ("%i\n", EOF);
It's not mentioned in any of the other answers so far, but you may need to press the right key combo (^D or ^Z) 2 or 3 times in order to actually signal EOF; see here for explanation.
putchar('%')
orprintf("%%")
c
.