[讨论]看看这个精妙的程序
看看这个精妙的程序 它是用来统计 单词、行数、与字符的 如果你自己写能这样写么 ?
#include <stdio.h>
#define IN 1
#define OUT 0
main(){
char c;
int 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 = IN; ++nw; } } printf("nl: %d nc: %d nw: %d \n",nl,nc,nw); getch(); }