当getchar()到达EOF时,main()不会返回 [英] main() does not return when getchar() reaches EOF

查看:165
本文介绍了当getchar()到达EOF时,main()不会返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我基本上从K& R复制了这个程序:


#include< stdio.h>

#include< stdlib.h>


int main()

{


int c;


while((c = getchar())!= EOF)

putchar(c);


返回0;

}


当我运行它时,我需要输入并在控制台上打印它,但是

不会退出。该计划继续运行。无论我输入什么,它都会继续运行。


这是Dev-C ++,使用gcc。这是编译器问题吗?

I essentially copied this program from K&R:

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

int main()
{

int c;

while ((c=getchar())!=EOF)
putchar(c);

return 0;
}

When I run it it takes my input and prints it on the console but
doesn''t exit. The program continues running. No matter what I input
it always continues running.

This is Dev-C++, uses gcc. Is it a compiler problem?

推荐答案

*搜索者:
我基本上从K& R复制了这个程序:

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

int main()
{
int c;

while((c = getchar())!= EOF)
putchar(c);

返回0;
}

当我运行它时,我需要输入并在控制台上打印它,但
不会退出。该计划继续运行。无论我输入什么,它都会继续运行。

这是Dev-C ++,使用gcc。这是编译器问题吗?
I essentially copied this program from K&R:

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

int main()
{

int c;

while ((c=getchar())!=EOF)
putchar(c);

return 0;
}

When I run it it takes my input and prints it on the console but
doesn''t exit. The program continues running. No matter what I input
it always continues running.

This is Dev-C++, uses gcc. Is it a compiler problem?




不,这是用户问题。具体来说,您永远不会生成

文件的结尾。在Unix中,使用Ctrl D提交零字节,然后将

解释为文件结尾;在Windows中,使用Ctrl Z后跟return,

,其中控制字符本身被解释为文件结尾。


-

答:因为它弄乱了人们通常阅读文字的顺序。

问:为什么这么糟糕?

A:热门发布。

问:usenet和电子邮件中最烦人的事情是什么?



No, it is a user problem. Specifically, you never generate an end of
file. In Unix, use Ctrl D to submit zero bytes, which is then
interpreted as end of file; in Windows, use Ctrl Z followed by return,
where the control character itself is interpreted as end of file.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


" Alf P. Steinbach" <人*** @ start.no>写在

新闻:4g ************* @ individual.net:
"Alf P. Steinbach" <al***@start.no> wrote in
news:4g*************@individual.net:
不,这是一个用户问题。具体来说,您永远不会生成文件结尾。在Unix中,使用Ctrl D提交零字节,然后将其解释为文件末尾;在Windows中,使用Ctrl Z后跟
返回,其中控制字符本身被解释为文件结尾。
No, it is a user problem. Specifically, you never generate an
end of file. In Unix, use Ctrl D to submit zero bytes, which is
then interpreted as end of file; in Windows, use Ctrl Z followed
by return, where the control character itself is interpreted as
end of file.




我明白了。谢谢。



I see. Thanks.


" Alf P. Steinbach" <人*** @ start.no>写道:
"Alf P. Steinbach" <al***@start.no> writes:
* Seeker:
我基本上从K& R复制了这个程序:
#include< stdio.h>
#include< ; stdlib.h>
int main()
{
int c;
while((c = getchar())!= EOF)
putchar(c) ;

返回0;
}
当我运行它时,我需要输入并在控制台上打印它,但
不会退出。该计划继续运行。无论我输入什么,它总是继续运行。
这是Dev-C ++,使用gcc。这是编译器问题吗?
I essentially copied this program from K&R:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int c;
while ((c=getchar())!=EOF)
putchar(c);

return 0;
}
When I run it it takes my input and prints it on the console but
doesn''t exit. The program continues running. No matter what I input
it always continues running.
This is Dev-C++, uses gcc. Is it a compiler problem?



不,这是用户问题。具体来说,您永远不会生成
文件的结尾。在Unix中,使用Ctrl D提交零字节,然后将其解释为文件末尾;在Windows中,使用Ctrl Z后跟return,
控制字符本身被解释为文件结尾。



No, it is a user problem. Specifically, you never generate an end of
file. In Unix, use Ctrl D to submit zero bytes, which is then
interpreted as end of file; in Windows, use Ctrl Z followed by return,
where the control character itself is interpreted as end of file.




< OT>

我不确定你的意思是提交零字节,但我不相信

这就是它的作用。

< / OT>


-

Keith Thompson(The_Other_Keith) ks *** @ mib.org < http://www.ghoti.net/~kst>

圣地亚哥超级计算机中心< *> < http://users.sdsc.edu/~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。



<OT>
I''m not sure what you mean by "submit zero bytes", but I don''t believe
that''s what it does.
</OT>

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.


这篇关于当getchar()到达EOF时,main()不会返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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