/////// Program lowercase.C /////// #include #include #include #include char lower(char c) { if ( isupper(c) ) return( tolower(c) ); else return(c); } void doio(istream& in, ostream& out) { char c; while (in.get(c)) out.put( lower(c) ); out.flush(); } int main (int argc, char* argv[]) { if ( argc == 1 ) // use standard I/O doio(cin, cout); else if ( argc == 3 ) // use files given { fstream infile(argv[1], ios::in); if ( infile.fail() ) { cerr << argv[0] << ":can't open input file " << argv[1] << "\n"; exit(1); } fstream ofile(argv[2], ios::out); if ( ofile.fail() ) { cerr << argv[0] << ":can't open output file " << argv[2] << "\n"; exit(1); } doio(infile, ofile); } else // error { cerr << "Usage: lower infile outfile \n"; exit(1); } return(0); } /////// End of lowercase.C ///////