Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ReadString from CStdioFile doesn't always!

Status
Not open for further replies.

bluecrush

Programmer
Mar 26, 2004
61
US
I'm reading a file using ReadString and it seems to skip some lines. The first 2 lines of the file are blank and it skips these, and then it reads 2 lines at once, then it reads a blank line, then skips a line of text, then starts to read normally (?). Can anybody think of anything that may be causing this?
 
Could you post some code showing an example of how you use it?


--
 
Sure...here's what I'm working with:

//declare file objects to read and write
CStdioFile sourceFile, destinationFile;

CFileException fileException;

//if the file doesn't exist prompt w/ error -- otherwise open it
if ( !sourceFile.Open(source,CFile::modeRead|CFile::typeBinary,&fileException ))
{
TRACE( "Can't open file %s, error = %u\n",source, fileException.m_cause );
}

//open destination file -- create if it doesn't exist
destinationFile.Open(destination,CFile::modeWrite|CFile::typeBinary|CFile::modeCreate);

//...do some stuff here

while(sourceFile.ReadString(Line0))
{

//...do some more stuff here

//if the investor code is '??????' or contains '???' then...
if ((Investor=="??????") || (Investor.Find("???") >= 0))
{


//if line3 doesn't contain 'XX' then write it
if (Line3.Find("XX") < 0 && Line3.Find("%%") < 0)
destinationFile.WriteString(Line3);

//if line2 doesn't contain 'XX' then write it
if (Line2.Find("XX") < 0 && Line2.Find("%%") < 0)
destinationFile.WriteString(Line2);

//if line1 doesn't contain 'XX' then write it
if (Line1.Find("XX") < 0 && Line1.Find("%%") < 0)
destinationFile.WriteString(Line1);

while(Line0.Find(char(12)) < 0)
{
//write line0
destinationFile.WriteString(Line0);

//read the next line into line0
sourceFile.ReadString(Line0);
}

//write line0
destinationFile.WriteString(Line0);

//...do some more stuff
}
else
{
Line3 = Line2;
Line2 = Line1;
Line1 = Line0;
}

...etc.

The file I'm reading looks similar to this:

Line 1: Some unwanted text on this line...
Line 2: A blank line
Line 3: Some more unwanted text...
Line 4: Another blank line...
Line 5: Some wanted text...

What it does on the first loop is read in the first 3 lines as one. Then on the second loop it reads in the 5th line!

I'm not sure if this helps at all but I'm not really doing anything that complex...I read in a line and look for certain information. If its there, I hold that line and read in 2 more lines to find a specific investor. If I find it, I read and write each line until I hit a page break. Then I start over.

Let me know if I can provide anymore information and thank you for your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top