elegant-code Posted on 2019-10-29 统计行数,单词书与字符串数, 这里对单词的定义 比较宽松, 他是任何不包含空格、制表符或者换行符序列。下面这段程序使 UNIX系统中wc程序的骨干部分。 123456789101112131415161718192021#include<stdio.h>#define IN 1 /*inside a word*/#define OUT 0 /*outside a word*//* count lines, words, and characters in input*/int main(){ int c, 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("%d %d %d", nl, nw, nc); }}