什么是EOF在C编程语言? [英] What is EOF in the C programming language?

查看:181
本文介绍了什么是EOF在C编程语言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你怎么能看到最后的打印?换句话说要放什么东西在EOF?我检查了定义和它说EOF是-1。

如果你输入Ctrl-D你不会看到任何东西。

 的#include<&stdio.h中GT;诠释主(){
 INT℃;
 而((C =的getchar()!= EOF)){
  的printf(%d个\\ N,C);
 }
 的printf(%d个 - 在EOF \\ n,C);
}


解决方案

在Linux系统和OS X,字符输入到导致EOF是<大骨节病>控制 - <大骨节病> D 。对于Windows,这是<大骨节病>控制 - <大骨节病>以Z

根据不同的操作系统上,这种性格会只有当它的第一个字符上线,即后<大骨节病>输入第一个字符工作。由于控制台输入常常是面向行的,该系统也可能无法识别EOF字符,直到以后你跟着它与<大骨节病>输入

是的,如果该字符识别为EOF,那么你的程序将永远不会看到实际的字符。相反,一个C程序将获得 1 的getchar()

How do you get to see the last print? In other words what to put in for EOF? I checked the definitions and it says EOF is -1.

And if you enter Ctrl-D you won't see anything.

#include <stdio.h>

int main() {
 int c;
 while((c = getchar() != EOF)) {
  printf("%d\n", c);
 }
 printf("%d - at EOF\n", c);
}

解决方案

On Linux systems and OS X, the character to input to cause an EOF is Ctrl-D. For Windows, it's Ctrl-Z.

Depending on the operating system, this character will only work if it's the first character on a line, i.e. the first character after an Enter. Since console input is often line-oriented, the system may also not recognize the EOF character until after you've followed it up with an Enter.

And yes, if that character is recognized as an EOF, then your program will never see the actual character. Instead, a C program will get a -1 from getchar().

这篇关于什么是EOF在C编程语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆