/////////////////////////////////////////////////////////////// // Proj2.C // // CMSC 341 - Fall 2001 Project 2 // // Kyu Bae xxx-xx-5868, Section 201 // // kyu_bae@yahoo.com / kbae1@umbc.edu // // Created : 20 September 201 // // Current : 1 October 2001 // /////////////////////////////////////////////////////////////// #include "dsexceptions.h" #include #include #include #include #include "Data.H" #include "LinkedList.H" ////////////////////////////////////////////////////////////// // Object: // This project will read data from a fie and build the // doubly circular linked // list. Ths data in the file consists ofcharacters/integer // pairs except the first entry which is a single integer. // This program will read the data from the file and store // each character/ // integer in the linked list in the order it was found in // the file. Characters represent a scamble message. This // program will print the message by moving from node to node // in the list based on the integer found in the node. The // integer might be positive and negative. ///////////////////////////////////////////////////////////// // Main(): // Read data from the file and inser into the list and // Print the message out by moving around the list .. // //////////////////////////////////////////////////////////// int main(int argc, char *argv[]) { // checking for the command line arguments if(argc != 2) { cerr << "Invalid number of command line argument\n" << "Usage is Proj2 \n" << "Aborting" << endl; exit(1); } //check for file open ifstream Infile(argv[1], ios::in); if (! Infile) { cerr << "cannot open " << argv[2] << " for input" << endl; cerr << "Program terminating" << endl; exit(1); } int nStart; char cData; char *token; char buffer[256]; List newList; ListItr itrZeroth = newList.zeroth(); Infile >> nStart; //checking for the blank lines if (nStart == 0) { cout << "List is Empty and Now Exiting Program!!" << endl << endl; exit(1); } while (Infile.getline(buffer, 255, '\n')) { if (strlen(buffer) == 0) // checking for the blank continue; cData = buffer[0]; token = strtok(&(buffer[1])," \t" ); newList.insert(Data(cData, atoi(token)), itrZeroth); //creating the Data object and inserting } Infile.close(); int i; Data tmpData; //descrambling the message while( nStart != 0 ) { if(nStart > 0) for (i = 0; i < nStart; i++) itrZeroth.advance();//moving forward else { nStart *= -1; for (i = 0; i < nStart; i++) itrZeroth.retreat();//moving backward } try { // throwing exceptions here tmpData = itrZeroth.retrieve(); } catch (BadIterator ex) { cout << "ERROR : " << endl; cout << "TRYING TO GET something there isn't there" << endl; } cout << tmpData; nStart = tmpData.getKey(); } cout << endl; return 0; } /////////////////////////////////////////////////////////// // THE END OF PROGRAM!!!!!! // ///////////////////////////////////////////////////////////