NetBeans控制台中的文件结尾方法(EOF)不起作用 [英] Methods to End Of File (EOF) not working in the NetBeans console

查看:133
本文介绍了NetBeans控制台中的文件结尾方法(EOF)不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在从K& Re2学习C。以上代码是我运行以进行确认的Pg18(信纸计数程序)中提到的代码。我尝试输入几个字符,然后按 ENTER ,但是它不起作用。然后我听说了 CTRL + Z CTRL + C CTRL + D ,其中 ENTER 表示文件结束。我在NetBeans控制台中尝试了此操作,但无法正常工作。我也尝试了 \0 \n ,可惜它也没有用。我已经搜索过了,但是所有人似乎都已经解决了 CTRL + Z CTRL + C CTRL + D ENTER 方法。我不明白这里出了什么问题。
PS:我使用Windows 7

I have been learning C from K&Re2. And the above code is what is mentioned in Pg18(Letter counting program), which I ran for confirmation purposes. I tried entering few characters and press ENTER, but it was not working. Then I heard about CTRL+Z,CTRL+C or CTRL+D with ENTER for End Of File. I tried it in NetBeans console, but it was not working. I tried \0 and \n too, pity it was not working too. I have searched for this, but all seemed to have solved the problem with CTRL+Z,CTRL+C or CTRL+D with ENTER method. I can't understand what is the problem here. PS: I use Windows 7

抱歉,没有直接插入代码。这是-

Sorry for not inserting code directly. Here is it-

#include <stdio.h>
#include <stdlib.h>

int main() {
    long c = 0;
    while (getchar() != EOF) {
        ++c;
    }
    printf("%ld", c);
    return 0;
}

在图像中,我尚未初始化的值长c 。抱歉该程序正在运行,但是我用于EOF的方法不起作用。

In the image, I have not initialized value of long c. Sorry for that. This program is running, but the methods I use for EOF doesn't work out.

编辑:
我尝试编译在NetBeans中运行,然后在cmd中而不是在NetBeans控制台中运行生成的.exe。 CTRL + Z 似乎有效!你们知道为什么它在NetBeans控制台中不起作用吗?

I have tried compiling in NetBeans, and then running the resulting .exe in cmd rather than in NetBeans console. CTRL+Z seems to work! Do you guys have any idea why it doesn't work in NetBeans console?

推荐答案

仅Windows

产品版本:NetBeans IDE 8.2(内部版本201609300101)

Product Version: NetBeans IDE 8.2 (Build 201609300101)

更新:NetBeans IDE已更新为版本NetBeans 8.2 Patch 2

Updates: NetBeans IDE is updated to version NetBeans 8.2 Patch 2

运行>设置项目配置>自定义...

Run > Set project configuration > Customize...

类别=运行

控制台类型=外部终端

外部终端类型=命令窗口

External Terminal Type = Command Window

单击应用,然后单击确定

Click Apply then OK

运行项目

要发送 EOF ,请按 ENTER ,然后 CTRL + D 或按两次 CTRL + D

To send EOF press ENTER then CTRL+D Or Press CTRL+D twice

这篇关于NetBeans控制台中的文件结尾方法(EOF)不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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