TCPL 阅读笔记 Chapter1

#include <stdio.h>
#define OUT 0
#define IN 1
int main(void)
{
	int c,state,nl,nc,nw;
	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("nl = %d,nw = %d, nc = %d\n",nl,nw,nc);
}
以上程序统计控制台中输入文本的字符数、单词数、行数。

你可能感兴趣的:(TCPL 阅读笔记 Chapter1)