Hi, all
I have a sample code like the following detailed:
//-----------------
FILE *fp1;
fp1=fopen("F:\\aa.dat","rb");
if(!feof(fp1))
{
// Step 1 :the following code is to read binary data from an
existing file
CString ss;
fread(ss.GetBuffer(1428),1428,1,fp1);
// Step 2: the following code is to test if the read action is
successful
fclose(fp1);
fp1 = fopen("F:\\bb.dat","wb+");
fwrite(ss,1428,1,fp1);
fclose(fp1);
// Step 3:the following code is to test the GetLength function!
int i;
i = ss.GetLength();
}
//-----------------------------
My question is : Why the value of i is 0, not the exact string
length? Could anybody tell me the root cause?
Thanks in advance!
Joseph
Joseph - 21 Jul 2006 08:02 GMT
I read the CString documents and I changed my code as below, but it still
does not work! I do not know why!
Line1: char *p1 = new char[1428];
Line2: fread(p1,1428,1,fp1);
Line3: CString str1(p1);
Line4: str1.ReleaseBuffer();
Line5: int i;
Line6: i = str1.GetLength();
// I found the value for i is 1 ,not 1428. Why?
but if I change line 2 to the following line ,it can work properly, why?
strcpy(p1,"ABCDEFG"); //not fread(p1,1428,1,fp1);
Could anybody give me a help?Help?
Thanks in advance!
Joseph
> Hi, all
> I have a sample code like the following detailed:
[quoted text clipped - 25 lines]
>
> Joseph
Joseph - 21 Jul 2006 08:20 GMT
Well , I got the root cause , it is because the file I read from is a binary
format file!
Joseph
>I read the CString documents and I changed my code as below, but it still
>does not work! I do not know why!
[quoted text clipped - 47 lines]
>>
>> Joseph