首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

以程序自身做输入的C程序,该怎么处理

2012-04-05 
以程序自身做输入的C程序#include stdio.h/* count digits, white space, others */main(){int c, i, nw

以程序自身做输入的C程序
#include <stdio.h>
/* count digits, white space, others */
main()
{
int c, i, nwhite, nother;
int ndigit[10];
nwhite = nother = 0;
for (i = 0; i < 10; ++i)
ndigit[i] = 0;
while ((c = getchar()) != EOF)
if (c >= '0' && c <= '9')
++ndigit[c-'0'];
else if (c == ' ' || c == '\n' || c == '\t')
++nwhite;
else
++nother;
printf("digits =");
for (i = 0; i < 10; ++i)
printf(" %d", ndigit[i]);
printf(", white space = %d, other = %d\n",
nwhite, nother);
}
The output of this program on itself is
digits = 9 3 0 0 0 0 0 0 0 1, white space = 123, other = 345
The declaration

以上是我在《The C programning language》中拷贝的一段代码,统计数字、空格、和其它字符,注意在运行的时候以程序自身做输入,如何以程序自身做输入呢?我用的是linux GCC 编译器,请高手指点,小弟在线雪地跪等答案。

[解决办法]
不懂。
[解决办法]
运行等待输入的时候, 把这个复制进去就行了

[解决办法]
这不就是输入直到输入eof为止吗……
[解决办法]
LZ 不知道如何在终端输入 EOF ?
Linux 下按 CTRL+D
Windows 下按 CTRL+Z

还有个更简单的办法是,比如源程序名叫 self.c ,编译之后的可执行文件叫 self ,那么终端下输入:

./self < self.c

也可以。

[解决办法]
注意在运行的时候以程序自身做输入

看不懂

热点排行