Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / July 2006

Tip: Looking for answers? Try searching our database.

Why I can not get the string buffer length ?Help!!!

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Joseph - 21 Jul 2006 04:31 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.