All, I have a problem where my program just hangs on a certain line, and I can't figure out why.
It's a command line app where it reads in a file and based on the user's arguments to the program, it will split the file into X seperate files.
To do this I read each line of the file using getline and stuff it into a string (not char) using string.append(). As I'm reading the file, I'm filtering out
certain values based on user args and duplicate rows.
After I've read the file in, I want to split it into X seperate files. First, I define an Array of Strings using malloc:
Code:
string *aOutputFiles;
if ((aOutputFiles = (string *) malloc ( intTempNumberFiles * sizeof *aOutputFiles )) == NULL) {
cerr << "\nError! Not enough memory to allocate buffer\n";
exit(EXIT_FAILURE);
}
Then I proceed to loop thru the string finding each NewLine value and stuffing it into the String Array:
Code:
intIterator = 0;
//now split the input file into multiple pieces
if (strInputFileContents.length() > 0) {
szFind=strInputFileContents.find_first_of("\n");
while (szFind!=string::npos) {
aOutputFiles[intIterator].append(strInputFileContents,0,(szFind+1)); //<--this is the line that breaks
//but not all the time...and if it does it's usually on the 2nd iteration of the loop
strInputFileContents.erase(0,(szFind+1));
szFind=strInputFileContents.find_first_of("\n");
if ( intIterator >= (intTempNumberFiles - 1) ) {
intIterator = 0;
} else {
intIterator = intIterator + 1;
}
}
}
Any ideas?
Also, if there's a better/faster way to do this please let me know also...
Thanks,
Brad