- 论坛徽章:
- 0
|
EOF在键盘上如何输入呢?
如下程序中:
#include<stdio.h>
main()
{
int c;
while ((c = getchar()) !=EOF)
putchar(c);
}回车就表示循环结束。
而如下程序:
#include <stdio.h>
#define IN 1 /* 在单词内 */
#define OUT 0 /* 在单词外 */
/* 统计输入的行数、单词数与字符数 */
main()
{
int c, nl, nc,nw, state;
state = OUT;
nl= nw = nc = 0;
while ((c = getchar()) != EOF) /* 循环结束的标志是什么 */
{
++nc;
if(c == '\n')
++nl;
if(c == ' ' || c == '\n' || c == '\t')
state=OUT;
else if (state == OUT)
{
state = IN;
++nw;
}
}
printf("%d %d %d\n", nl, nw, nc);
}
什么输入表示循环结束呢?
小弟新手,还望各位指点! |
|