====== wc ====== #include #include #include #include using namespace std; int main( int argc, char * argv [] ) { ifstream in; int ch, words = 0, lines = 0, chars = 0, inWord = 0; if ( argc != 2 ) { cout << "wc " << endl; return ( 1 ); } in . open ( argv[1], ios::in ); if ( ! in . good () ) { cout << "Chyba cteni " << argv[1] << endl; return ( 1 ); } while ( 1 ) { ch = in . get (); if ( in . eof () ) break; chars ++; if ( ch == '\n' ) lines ++; if ( inWord ) { if ( isspace ( ch ) ) inWord = 0; } else { if ( ! isspace ( ch ) ) { words ++; inWord = 1; } } } if ( chars ) lines ++; cout << argv[1] << ": " << lines << " " << words << " " << chars << endl; in.close(); return ( EXIT_SUCCESS ); }