/////////////////////////////////////////////////////////////// // // // top.cpp - send first few file lines to output // // // // version: 1.2 // // Language: Borland C++, ver 5.0 // // Platform: Dell Pentium 200, Windows NT 4.0 // // Application: CSE687 Example // // Author: Jim Fawcett // // CST 2-187, (315) 443-3948 // // fawcett@neptune.syr.edu // /////////////////////////////////////////////////////////////// /* usage: top [-15] file1.hpp file2.cpp .. */ /////////////////////////////////////////////////////////////// // Build Process // // ------------- // // Files required: // // top.cpp, strs.hpp, strs.cpp // // // // build command: // // cl /GX top.cpp strs.cpp /link setargv.obj // // // /////////////////////////////////////////////////////////////// /* Maintenance History ------------------- ver 1.2 : 24 Jan 99 - replaced Borland build process with Visual C++ build ver 1.1 : 09 Jan 98 - cosmetic modifications to this page ver 1.0 : 24 Dec 95 - first release */ // #include // ifstream(), >>, <<, cout #include // atoi() #include "strs.h" // string definitions static int dispLines = 10; // default number of lines to display, has file scope, e.g., // defined in static memory and globally visible in this file only //----< display top few lines of file >------------------------ void showTop(char *fileName) { // open file ifstream in(fileName); if(!in.good()) { cerr << "can't open file " << fileName << endl; return; } // announce file name to output cout << fileName << endl; // read dispLines strings from the top of input file // and send to standard output static str s; // static local variable defined in static // memory, exists for program lifetime // has internal character memory allocated // on heap (see strs.cpp, strAlloc() function int j; // local variable, defined on showTop's stack // frame and is redefined for each invocation for(j=0; j> s; if(!in.good()) break; cout << s << endl; } cout << endl; } //----< process commands and display files >------------------- void main(int argc, char *argv[]) { int i; // defined on main's stack frame for(i=1; i