Hiho,
I want to read the content of a binary file into a string. It works, but
only the first 4 chars are left after the reading and the stringsize is,
of course, 4 bytes.
I got this method from a tutorial and though it works...what's wrong? Is
the buffersize for the String 'FileContent' not ok? Before fread the
size of 'FileContent' is correct, but after the operation its truncated
to 4.
The Codepart
--------------------------------------
int fsize;
CString FileContent;
LPTSTR pStr;
FILE *fl = fopen(ff,"rb");
if(!fl)
{
//Error Message
}
else
{
fseek(fl, 0, SEEK_END);
fsize = ftell(fl);
pStr = FileContent.Get BufferSetLength ((int)fsize + 1);
fseek(fl, 0, SEEK_SET);
c_edit1.SetWind owText(itoa(fsi ze, buf, 100));
fsize = fread(pStr, 1, fsize, fl);
*(pStr + fsize) = '\0';
FileContent.Rel easeBuffer(-1);
}
fclose(fl);
--------------------------------------
Thanks for your help!
Axel
I want to read the content of a binary file into a string. It works, but
only the first 4 chars are left after the reading and the stringsize is,
of course, 4 bytes.
I got this method from a tutorial and though it works...what's wrong? Is
the buffersize for the String 'FileContent' not ok? Before fread the
size of 'FileContent' is correct, but after the operation its truncated
to 4.
The Codepart
--------------------------------------
int fsize;
CString FileContent;
LPTSTR pStr;
FILE *fl = fopen(ff,"rb");
if(!fl)
{
//Error Message
}
else
{
fseek(fl, 0, SEEK_END);
fsize = ftell(fl);
pStr = FileContent.Get BufferSetLength ((int)fsize + 1);
fseek(fl, 0, SEEK_SET);
c_edit1.SetWind owText(itoa(fsi ze, buf, 100));
fsize = fread(pStr, 1, fsize, fl);
*(pStr + fsize) = '\0';
FileContent.Rel easeBuffer(-1);
}
fclose(fl);
--------------------------------------
Thanks for your help!
Axel
Comment