5

while reading from k&r i came across the following example

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

doubt 1:when i am typing the character ctrl+z(EOF on my sys) . o/p is hello
but when i am typing the string of characters like abcdef^Zghijk
o/p is abcdef->(including the arrow) and waiting for user to enter i/p instead of terminating loop and print hello..

Tarun
  • 3,162
  • 3
  • 29
  • 45

1 Answers1

5

ctrl+z is not EOF, it is just a way to tell your terminal to close the stream.

On Windows systems you need to write the ctrl+z as the first character of the line, otherwise the terminal considers it to be an ordinary character.

hrnt
  • 9,882
  • 2
  • 31
  • 38
  • But i have doubt that if its been treated like a ordinary variable then why o/p stop after abcdef->..instead of abcdef^zjhijk – Tarun Mar 29 '11 at 14:51