T
Tim Müller
Hello,
I am using Borland Turbo C++ Version 3.1 for Windows with the stream
libraries included with this package.
I am trying to read and find textlables in a text file, with this
code:
BOOL FindLabel (ifstream& InputFile, char* Lable)
{
char InBuffer[81];
if (!InputFile.eof()) InputFile.getline(InBuffer,81);
while ( strcmp (InBuffer, Lable) && !InputFile.eof() )
{
InputFile.getline(InBuffer, 81);
}
if (strcmp(Lable, InBuffer)==0 && !InputFile.eof() ) return TRUE;
else return FALSE;
}
// extract of WinMain-function
{
....
ifstream InputFile ("Testfile.txt");
InputFile.seekg(0); // sets streampointer to beginning of the file
FindLable(InputFile, "Test1");
InputFile.seekg(0); // sets streampointer to beginning of the file
FindLable(InputFile, "Test2");
....
}
If my test file looks like
case1
Test2
Test1
end
both lables are found.
If it looks like
case2
Test2
Test
end
lable "Test2" is not found, because InputFile.good() goes to FALSE,
and InputFile.seekg(0) doesn't work anymore.
In case2, FindLable searches until the end of the file while trying to
find "Test1", InputFile.eof() becomes TRUE, and then seekg(0) doesn't
work anymore.
How could I set the streampointer of ifstream back to position 0,
after I read until eof?
Best regards
TM
I am using Borland Turbo C++ Version 3.1 for Windows with the stream
libraries included with this package.
I am trying to read and find textlables in a text file, with this
code:
BOOL FindLabel (ifstream& InputFile, char* Lable)
{
char InBuffer[81];
if (!InputFile.eof()) InputFile.getline(InBuffer,81);
while ( strcmp (InBuffer, Lable) && !InputFile.eof() )
{
InputFile.getline(InBuffer, 81);
}
if (strcmp(Lable, InBuffer)==0 && !InputFile.eof() ) return TRUE;
else return FALSE;
}
// extract of WinMain-function
{
....
ifstream InputFile ("Testfile.txt");
InputFile.seekg(0); // sets streampointer to beginning of the file
FindLable(InputFile, "Test1");
InputFile.seekg(0); // sets streampointer to beginning of the file
FindLable(InputFile, "Test2");
....
}
If my test file looks like
case1
Test2
Test1
end
both lables are found.
If it looks like
case2
Test2
Test
end
lable "Test2" is not found, because InputFile.good() goes to FALSE,
and InputFile.seekg(0) doesn't work anymore.
In case2, FindLable searches until the end of the file while trying to
find "Test1", InputFile.eof() becomes TRUE, and then seekg(0) doesn't
work anymore.
How could I set the streampointer of ifstream back to position 0,
after I read until eof?
Best regards
TM