Hi
I'm having a problem reading in a file. I am using BCB6 Personal Edition under Win XP. The file is always read correctly up to the 4413th byte then the data is corrupted. I have modified the code from a fixed array size to use a vector so I have been able to confirm that the correct number of bytes is read in and there is more than sufficient memory available.
My apologies for the formatting, I've tried to reduce the word wrap as much as possible
FileHandler InputBinFile;
AnsiString InputFileName;
unsigned int byteCount=0;
char tempChar1; //debug
char tempChar2; //debug
unsigned int testSize; //debug
//get filename
InputFileName = FileOpen1->Dialog->FileName;
//open file to read data in
unsigned int fileErr = InputBinFile.openInputFile(InputFileName);
if(fileErr==0){
if(!(InputBinFile.isOpen())){ // check file is open
MapEditorSB->Panels->Items[0]->Text = "Error- No File Open";
return;
}
BinFileSize = InputBinFile.getLength();
// copy file to array
InputBinFile.goToBeg();
DataHexArray.clear();
testSize = (unsigned int) DataHexArray.max_size();
while(byteCount!=BinFileSize){
DataHexArray.push_back(InputBinFile.getChar byteCount));
byteCount++;
}
testSize = (unsigned int) DataHexArray.size();
tempChar1 = DataHexArray[4412];
tempChar1 = DataHexArray[4413];
InputBinFile.closeFile();
// display filename and close file
MapEditorSB->Panels->Items[0]->Text = InputFileName;
InputBinFile.closeFile();
}//end if isOpen
else{ //filErr==1
MapEditorSB->Panels->Items[0]->Text = "Error - Can't open file";
}
}
The filehandler is a class using fstream it reads a character in using the following method:
unsigned char FileHandler::getChar(unsigned int position)
{
unsigned char inData;
FileHandlerFile.seekg(position,ios::beg);
FileHandlerFile.read(reinterpret_cast<char*>( &inData ),1); //retrieve one character at a time
return inData;
}
TIA
James