How do we terminate this code?
This c code is from K&R. It runs continuously even when I type -1. I am using eclipse on fedora 17. What is wrong with this code? how will it end? Even CTRL + D doesn't work to finish it!
#include<stdio.h>
int main(void)
{
int c;
c = getchar();
while(c != EOF)
{
putchar(c);
c = getchar();
}
return 0;
}
source to share
It runs continuously even when I print -1
On Unix, you need to type Ctrl-D instead to pass the end of the file.
As Mooing Duck points out, this seems to be a bug in Eclipse .
source to share
Turned out to be a problem with the Eclipse IDE. external eclipse, the code works fine. CTRL + D for unix is EOF (inside -1). There is a workaround in eclipse. for each application that requires EOF go to RUN -> RUN CONFIGURATION ... -> in the main tab, scroll down and uncheck "connect process input and bring it to terminal". now run the code. CTRL + D should work. you must apply this trick separately for each application.
source to share