标签:
#include<stdio.h>
#define STOP ‘|‘
#include<ctype.h>
int main()
{
char ch;
char prev;
long n_chars=0L;
int n_lines=0;
int p_lines=0;
int n_words=0;
bool inword=false;
printf("Enter text to be test(| to quit)\n");
while((ch=getchar())!=STOP)
{
n_chars++;
if(ch==‘\n‘)
{
n_lines++;
}
// 下面的两个if相互制约 主要是控制一个单词的开始和结束
if(!isspace(ch)&&!inword)
{
inword=true;
n_words++;
}
if(isspace(ch)&&inword)
{
inword=false;
}
prev=ch;
}
if(prev!=‘\n‘)
p_lines++;
printf("character=%ld lines=%d plines==%d words=%d",n_chars,n_lines,p_lines,n_words);
}
标签:
原文地址:http://www.cnblogs.com/HJL085/p/5295124.html