当前位置: 代码迷 >> C语言 >> 怎样才能看到结果
  详细解决方案

怎样才能看到结果

热度:179   发布时间:2006-07-23 22:44:42.0
怎样才能看到结果

我用的是WIN-TC编译的
#include "stdio.h"
#include "conio.h"

main()
{
int c,nt,nr;

nt = 0;
nr = 0;
while ( (c= getchar()) != EOF)
if ( c == '\n') {
++nr;
}
if ( c == '\t') {
++nt;
}
printf("%d %d\n",nr,nt);
getch();
}
统计输入中换行符和制表符的个数,运行时我按回车键和TAB键后,没有执行printf那句,只有CTRL+C退出,我怎样才能看到结果呢?谢谢各位!

搜索更多相关的解决方案: 结果  

----------------解决方案--------------------------------------------------------
请问楼主一句,您知道eof表示什么意思吗?
----------------解决方案--------------------------------------------------------

eof means end of file.
所以您完全没必要这么用.
EOF是整型数据-1,与您所用的字符c完全是两个不同的类型,您说这这样能退出来?
#include "stdio.h"
#include "conio.h"main()
{
int c,nt,nr;

nt = 0;
nr = 0;
while ( (c= getchar()) != '#')
{
if ( c == '\n')
++nr;
if ( c == '\t')
++nt;
}
printf("%d %d\n",nr,nt);
getch();
}


----------------解决方案--------------------------------------------------------
EOF is end of file

windows is Ctrl+d
Linux is Ctrl+z

----------------解决方案--------------------------------------------------------
windows is Ctrl+d
Linux is Ctrl+z

====>

reverse

----------------解决方案--------------------------------------------------------
    首先,我定的c不是char,是int,而且,我照你的把EOF改成#也不行,CTRL+d也不行啊
----------------解决方案--------------------------------------------------------

完了,错了.非常抱歉,那您再用ctrl+z试试这个程序。
#include "stdio.h"
#include "conio.h"
main()
{
int c,nt,nr;

nt = 0;
nr = 0;
while ( (c= getchar()) != EOF)
{
if ( c == '\n')
++nr;
if ( c == '\t')
++nt;
}
printf("%d %d\n",nr,nt);
getch();
}


----------------解决方案--------------------------------------------------------
EOF是整型数据-1,也就是十六进制数据ffff,标准输出的EOF通过键盘的^Z来产生
----------------解决方案--------------------------------------------------------
至于Linux操作系统,俺就不知了。
----------------解决方案--------------------------------------------------------
     我是在win2000下运行的,ctrl+z也不行
----------------解决方案--------------------------------------------------------
  相关解决方案