-3

i was studying EOF character in c and came across a program :

#include <stdio.h>
main()
{
int c= 0;
while((c = getchar())!=EOF)
putchar(c);
}

its all good it is giving proper o/p but how do i come out of the loop by entering a EOF character which i entered and it did nothing.

amol
  • 87
  • 1
  • 12

2 Answers2

4

To stimulate EOF in stdin,

  • If you are on windows or DOS press CTRL+Z
  • Or if you are running linux or some other OS, press CTRL+D
Spikatrix
  • 20,225
  • 7
  • 37
  • 83
  • Under some environments, it is necessary to enter CTRL-Z twice. It is also usually best to precede the CTRL-Z (single or pair) or CTRL-D with the enter key, to avoid the last line of input being discarded. – Rob Feb 07 '15 at 09:21
0

I dont think there is an EOF character,and CTRL+Z and CTRL+D are used to inform the OS for termination. Follow these links it has the answers Representing EOF in C code? End of File (EOF) in C

Community
  • 1
  • 1
AnoopDV
  • 305
  • 1
  • 3
  • 13