确定EOF表达 [英] Determining EOF expression

查看:116
本文介绍了确定EOF表达的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要验证表达式 getchar()! = EOF 0 1
我当前的代码:

I need to verify that the expression getchar() ! = EOF is 0 or 1. My current code:

#include <stdio.h>
int main (int argc, char *argv[])
{
    int c;
    while (( c= getchar()) != EOF) 
    {
        printf("%d ", c != EOF);
        putchar(c);
    }
    printf("\n%d\n", c != EOF);
}

当我尝试运行时,我会得到

When I try to run that I get

98980980
1 91 81 91 81 01 91 81 01 

我不确定我是否正确。

编辑:

好,问题实际上是如何生成EOF
,解决方案是按ctrl + D。

Ok the question was actually " How to generate EOF " and the solution was to press ctrl+D.

推荐答案

我不太确定您是否要这个答案,但是据我了解,您正在寻找什么信息

I'm not very sure if you want this answer, but as per my understanding, what information you're looking for is


  • 如果输入任何有效字符,则 getchar()!= EOF 会产生1。

  • 如果按 CTRL + D (在Linux上),或 CTRL + Z (在Windows上),它将生成 EOF getchar()!= EOF 得出0。

  • If you input any valid character, getchar() != EOF yields 1.
  • If you press CTRL+D (on linux), or CTRL+Z (on windows), it will generate EOF and getchar() != EOF yields 0.

这篇关于确定EOF表达的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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