为什么 Ctrl-Z 不会触发 EOF? [英] Why Ctrl-Z does not trigger EOF?

查看:21
本文介绍了为什么 Ctrl-Z 不会触发 EOF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么Ctrl+Z不触发循环完成下面的小程序?

Why Ctrl+Z does not trigger the loop to finish on the following small program?

#include <stdio.h>

main()
{
    int c;
    while ((c = getchar()) != EOF)
    {
        //nothing 
    }

    return 0;
}

如果我输入:test^ZEnter,它不会退出循环.

If I enter: test^ZEnter, it does not get out of the loop.

我在(此处这里) 但没有为 Windows 下的 C(不是 C++)解释它.

I found related questions around (here and here) but none to explain it for C (not C++) under Windows.

注意:我在 Windows 8.1 上使用 Visual Studio 2015 PRE

Note: I use Visual Studio 2015 PRE on a windows 8.1

推荐答案

您需要按 Enter 然后使用 ctrl+Z 和然后再次输入.

You need to hit Enter and then use ctrl+Z and then Enter again.

或者,您也可以使用 F6

这篇关于为什么 Ctrl-Z 不会触发 EOF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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