Greetings!
I ran into a problem again.
I'd like to read from a file, I read the data, and I get extra characters to the end of the data! My code is the following:
Code:
void __fastcall TfrmMain::mainbetolt(TObject *Sender)
{
char *dataBuffer;
try {
int iFileHandle = FileOpen("config.dat", fmOpenReadWrite);
int iFileLength = FileSeek(iFileHandle,0,2);
int i=0;
FileSeek(iFileHandle,0,0);
dataBuffer=new char[iFileLength];
dataBuffer="";
int iBytesRead = FileRead(iFileHandle, dataBuffer,iFileLength);
if (iBytesRead != iFileLength)
{ ShowMessage("Nem megfelelő számú beolvasott byte.");}
ShowMessage(dataBuffer);
frmMunkadir->txtMunkadir->Text=dataBuffer;
FileClose(iFileHandle);
delete [] dataBuffer;
}
catch(...)
{
ShowMessage("Fájlműveleti hiba");
}
}
As you see, I define a char *Buffer here, which is a pointer of yet undefined elements. (chars)
And when I open the "config.dat" file as specified above, I get the contents of it, plus the characters "műveleti hiba" to the end of the Buffer.
The two weird things are:
-the Buffer, is LONGER with Length("műveleti hiba") characters, than I've defined it - it was defined to be the same length as the file content
-the extra characters come from THIS code! How could this be?
Please help me with this!
Thanks again
Han