#include <stdio.h>
#include <ctype.h>
#include <stdbool.h>
#define STOP '|'
int main () {
char c;
int n_lines =0;
int n_words =0;
char n_chars = 0;
bool inword = false; //如果c在单词中,则为true
while((c =getchar())!= STOP)
{
n_chars++;// 每输入一个字符统计一次
if(c =='\n') //换行符
{
n_lines++;
}
if(!isspace(c)&&!inword)//输入单词就+1
{
inword =true; //开始一个新的单词
n_words++;
}
if(isspace(c)&&inword)
{
inword =false;
}
}
printf("字符数 %d 单词数 %d 行数 %d ",n_chars,n_words,n_lines);
return 0;
}