为什么使用EOF统计字符无法输出
  • 板块灌水区
  • 楼主xjyilyoooo
  • 当前回复10
  • 已保存回复10
  • 发布时间2022/3/17 11:11
  • 上次更新2023/10/28 06:24:41
查看原帖
为什么使用EOF统计字符无法输出
674071
xjyilyoooo楼主2022/3/17 11:11
#include <stdio.h>

#define In 1
#define Out 0

int main() {
    int c,nl,nw,nc,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 = Out;
            ++nw;
        }
    }
    printf("%d %d %d\n",nl,nw,nc);

    return 0;
}
2022/3/17 11:11
加载中...