K&安培; R,怎么读的getchar EOF [英] k&R,how getchar read EOF

查看:183
本文介绍了K&安培; R,怎么读的getchar EOF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

而来自K&放阅读; R我碰到下面的例子

while reading from k&r i came across the following example

#include<stdio.h>
int main()
{
int c;
while((c=getchar())!=EOF)
{
    putchar(c);
}
printf("hello");
}

1疑问:当我键入字符CTRL + Z(EOF我SYS)。 O / P为hello结果
但是当我打字像ABCDEF ^ Zghijk结果的一串字符
O / P是ABCDEF - >(包括箭头),并等待用户输入的I / P,而不是终止循环和打印你好..

doubt 1:when i am typing the character ctrl+z(EOF on my sys) . o/p is hello
but when i am typing the string of characters like abcdef^Zghijk
o/p is abcdef->(including the arrow) and waiting for user to enter i/p instead of terminating loop and print hello..

推荐答案

CTRL + Z 不是EOF,它只是一种方法来告诉你的终端以关闭流。

ctrl+z is not EOF, it is just a way to tell your terminal to close the stream.

在你需要编写Windows系统上的 CTRL + Z 作为该行的第一个字符,否则端子认为它是一个普通的字符。

On Windows systems you need to write the ctrl+z as the first character of the line, otherwise the terminal considers it to be an ordinary character.

这篇关于K&安培; R,怎么读的getchar EOF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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