// CS1320-5 // 1999 Oct 28 // scribed by Geoffrey Derber and Jeffrey D. Oldham // N-Way Merge Program // This program merges the lines of files together, sending them to // the standard output. // The program repeatedly prints one line from each of the files // specified on the command line. For example, if the files specified // on the command line are file0, file1, file2, and file2, it produces // the following output: // first line of file0 // first line of file1 // first line of file2 // first line of file3 // second line of file0 // second line of file1 // second line of file2 // second line of file3 // ... // If a file contains no more lines, it does not affect the output. // If no files are specified, the program produces no output. #include #include #include int main(int argc, char *argv[]) // the file names are argv[1], ..., // argv[argc-1] { // The main data structure! // We will use an array of file streams. // The ifstream file_list[i] corresponds to the file with name // argv[i+1]. ifstream file_list[1000]; for(int x=0;x