How to simulate an EOF?
Solution 1:
To enter an EOF, use:
- ^Z (CtrlZ) in Windows
- ^D on Unix-like systems
Solution 2:
Refer EOF
Windows: Ctrl+Z
Unix :Ctrl+D
Solution 3:
First, press: Ctrl^X, next: Ctrl^D
Solution 4:
You can also simulate EOF by explicitly giving int variable a value of -1.
Check out this code for more clarity:
#include<stdio.h>
int main() {
// char ch=getchar()
// int ch=-1;
if(ch==EOF) { printf("\nEOF: %d",EOF); }
if((ch!=EOF)==0) { printf("\nit is equal to 0"); }
if((ch!=EOF)==1) { printf("\nit is equal to 1"); }
else { printf("\n it is equal to other value"); }
system("pause");
return 0;
}
Solution 5:
I had the same problem after pressing Ctrl+d program stopped and returned 0. If you use Clion press Ctrl+Shift+a than type Registry press enter and make sure run.processes.with.pty. is unchecked. After that compile program again and then you can type in input but don't press Ctrl+d on the same line as input it will return 0 or Error.