xtremee Posted October 1, 2007 Share Posted October 1, 2007 Hi all,I have this C++ code for a program that divide the big files to a small one that have a logic error that i can't find it.so, i wanna to know where is this logical error? so that i can modifiy this code.Here is the code:#include <iostream>#include <fstream>#include <sstream>#include <string>using namespace std;int main (int argc, char *argv[]) { if (argc < 2) { cout<<" feilsPart: no input file\n"; return 1; } else if (argc < 3) { cout<<" feilsPart: no size for the part file in Bytes\n"; return 1; } else if (argc < 4) { cout<<" feilsPart: no initial name for Part files\n"; return 1; } else if (argc < 5) { cout<<" feilsPart: no extention for Part files\n"; return 1; } else { string inputFileName = argv[1]; // the name of the input file int partSize = atoi(argv[2]); // the size of the part files string partInitialName = argv[3]; // the initial name for part files. string partExtention = argv[4]; // the extention name for the part files. // open the Big file ifstream inputFile (inputFileName.c_str()); if (inputFile.is_open()) { // counter to use in nameing of the part files. int partCounter = 1; while(!inputFile.eof()) { bool fileIsNotFull = true; // to save some part of the big file it , then add it to the part file. string somePart; ostringstream oss; oss <<partInitialName<<partCounter<<"."<<partExtention ; // the name of the part file is ready to use. string PartFileName = oss.str(); // open the part file. ofstream partFile (PartFileName.c_str()); // counter for the size of the part file. int partSizeCounter = 0; if (partFile.is_open()) { while ( (!(partSizeCounter > partSize) && !(partSizeCounter+somePart.size() > partSize)) && fileIsNotFull ) { getline (inputFile,somePart); if ( (somePart.size()+ partSizeCounter) < partSize ) { partSizeCounter += somePart.size(); partFile<<somePart<<endl; } else fileIsNotFull = false; cout<<"\r "<<partSizeCounter; } partFile.close(); cout<<"\r feilsPart: "<<PartFileName<<" Don . size = "<<partSizeCounter<<" Byets"<<endl; } // encrese the part counter to change the File name. partCounter++; } // end of input file. inputFile.close(); cout<<" feilsPart: Finished.."; } // Big file is open else else cout<<" feilsPart: Input file \""<<inputFileName<<"\" can not open\n"; } // argc return 0;} Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now