C : How to simulate an EOF?

我们两清 提交于 2019-11-26 10:29:44
Greg Hewgill

To enter an EOF, use:

  1. ^Z (CtrlZ) in Windows
  2. ^D on Unix-like systems

Refer EOF

Windows: Ctrl+Z
Unix :Ctrl+D

First, press: Ctrl^X, next: Ctrl^D

Shivam Agarwal

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;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!