/* ** wc.cpp - count of lines, words & characters from standard input. */ #include using namespace std; int main( void ) { unsigned long nl = 0L; /* #lines */ unsigned long nw = 0L; /* #words */ unsigned long nc = 0L; /* #chars */ char c; bool inword = false; /* True only when inside a word */ for (;;) { cin >> noskipws >> c; if ( cin.eof() ) break; ++nc; if ( c == '\n' ) { ++nl; } if ( c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\v' || c == '\f' ) /* if whitespace */ { inword = false; } else if ( !inword ) { inword = true; ++nw; } } cout << nl << " lines, " << nw << " words, " << nc << " chars" << endl; }