I am trying to load and process a large text file one page at a time (seperated by a form feed). Problem is that the character array that I am feeding the data into with a getline fills up after a couple of pages. It should only be drawing one page at a time and therefore no more than one page should ever be in the buffer at a time. I have verified that the getPage function does return just one page, however after two calls to it, the function returns blanks.
My guess is that the character buffer is not resetting each time the function is called and therefore it is getting full.
Any thoughts would be greatly appreciated.
- flub
My guess is that the character buffer is not resetting each time the function is called and therefore it is getting full.
Any thoughts would be greatly appreciated.
- flub
Code:
int main ()
{
//Variable Declarations ------//
string DataFileName = "filename.txt",
Path="./",
FullFileName;
string page;
ifstream datfile;
// Process the data file -----//
// open the file
FullFileName = Path + DataFileName;
datfile.open(FullFileName.c_str());
if (!datfile.is_open())
{
cout << "An error occured opening the data file.\nPlease make sure that the data file is present and run program again\n";
return(-1);
}
// get the first page
page = getPage(datfile);
// search for the first instance of "BRANCH"
while (!findString(page, "BRANCH"))
{
// get the next page
page = getPage(datfile);
// display the page
cout << endl << page << endl;
}
datfile.close();
return (1);
}
string getPage (ifstream &infile)
{
char ff = char(0x0c);
const int SIZE = 4800;
char *buffer = new char[SIZE];
infile.getline (buffer, SIZE, ff);
return (buffer);
}