统计输入的行数,单词数和字符数

#include<stdio.h>
#define IN 1 /*在单词内*/
#define OUT 0 /*在单词外*/
//统计输入的行数,单词数和字符数
int main(){
    int c, nl, nw, nc, state;
    nw=nl=nc=0;
    state=OUT;
    while((c=getchar())!=EOF){
        nc++;
        if(c=='\n')
            nl++;
        if(c=='\n' || c=='\t' || c==' '){
            state=OUT;
        }
        else if(state==OUT){
            state=IN;
            nw++;
        }
    }
    printf("%d %d %d\n",nl,nw,nc);
    getchar();
    getchar();
    return 0;
}

实验结果

统计输入的行数,单词数和字符数

相关文章:

  • 2021-10-12
  • 2021-11-28
  • 2021-11-27
  • 2022-01-29
  • 2022-12-23
  • 2022-12-23
  • 2021-05-04
猜你喜欢
  • 2021-11-23
  • 2022-02-25
  • 2022-02-18
  • 2022-01-21
  • 2022-01-15
  • 2021-09-16
相关资源
相似解决方案