我没有得到任何输出.您能告诉我EOF何时终止.这是什么错误? [英] I didn't get any ouput. could you tell me when the EOF will terminate.what is the error?

查看:93
本文介绍了我没有得到任何输出.您能告诉我EOF何时终止.这是什么错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include<stdio.h>
#include<conio.h>
#include<string.h>
//#define nl 0
void main()
{
	int No_Lines=0,No_Words=0,No_Letters=0,No_Sentence=0;
	int Letter;
	while((Letter=getchar())!=EOF)
	{
		if(Letter=='' '')
			++No_Words;
		else if(Letter==''\n'')
			++No_Lines;
		else if(Letter==''.'')
			++No_Sentence;

	}
	printf("Words\tLines\tSentence\n");
	printf("%d\t%d\t%d",No_Words,No_Lines,No_Sentence);
	getch();
}



[edit]已添加代码块-OriginalGriff [/edit]
[edit2 + 3]摆脱该死的关闭标签! rr! -OriginalGriff [/edit 2 + 3]

解决方案

尝试键入CTRL + Z:如果不起作用,请尝试CTRL + C,但这可能只是


此应用程序不执行任何操作... getchar()旨在从stdin抓取输入,默认情况下是用户输入,但您不要求用户进行输入(我想您可以将它写在屏幕上).另外,您尝试读取用户输入,直到EOF为止,这没有意义,因为stdin不是文件,所以您最终将陷入无限循环.

参见以下示例:
http://www.cplusplus.com/reference/clibrary/cstdio/getchar/ [ ^ ]


#include<stdio.h>
#include<conio.h>
#include<string.h>
//#define nl 0
void main()
{
	int No_Lines=0,No_Words=0,No_Letters=0,No_Sentence=0;
	int Letter;
	while((Letter=getchar())!=EOF)
	{
		if(Letter=='' '')
			++No_Words;
		else if(Letter==''\n'')
			++No_Lines;
		else if(Letter==''.'')
			++No_Sentence;

	}
	printf("Words\tLines\tSentence\n");
	printf("%d\t%d\t%d",No_Words,No_Lines,No_Sentence);
	getch();
}



[edit]Code Block added - OriginalGriff[/edit]
[edit2 + 3]Get rid of damn close tags! Grrrr! - OriginalGriff[/edit 2 + 3]

解决方案

Try typing a CTRL+Z: if that doesn''t work, try CTRL+C, but that may just kill your app.


This application does nothing... getchar() is meant to grab input from stdin, which is the user input by default, yet you don''t ask the user for input (I guess you can write it on the screen it in if you knew to do it). Additionally, you try to read the user input until EOF, that doesn''t make sense, since stdin not a file, so you''ll end up stuck in that infinite loop.

See this example:
http://www.cplusplus.com/reference/clibrary/cstdio/getchar/[^]


这篇关于我没有得到任何输出.您能告诉我EOF何时终止.这是什么错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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