Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Nov 2005

    The error of read data from file

    Hi everybody!
    Recent I encountered two problems.
    First problem:
    I used fread/fwrite function of the standard c, to read or write a structure like:
    typedef struct
    TUint8 i;
    TUint8 j;
    }Teststructure ;
    to a file.when I debug program in simulator ,the file cursor move ahead 2 bytes but move ahead 4 bytes when in real device. So I try to write a TUint8 data to a file ,I find the file cursor move ahead 1 bytes no matter in simulator or real device. I describe in form code like below:

    Teststructure * b;
    FILE* fp = fopen(filePath,"wb");
    fwrite( b;sizeof(Teststructure),1, fp);

    //I suppose the file cursor start at 0;
    TInt addr1 = ftell(fp);

    In simulator
    addr1 = 2;
    In real device
    addr1 = 4;

    And another code
    TUint8 i = 2;
    FILE* fp = fopen(filePath2,"wb");
    TInt addr2 = ftell(fp);

    No matter in simulator or real device
    addr2 = 1;
    Who can tell me why this happen?

    Another problem,
    I write a TReal data to file:
    TReal i = 0.22;
    FILE* fp = fopen(filePath,"wb");
    fwrite(&i,sizeof(TReal ),1,fp);
    Then, I read this TReal data from file:
    TReal j;
    FILE* fp = fopen(filePath,"rb"):
    in simulator j = 0.22;but in real device the value of j was a incorrect value;
    who can tell me why?

    My platform is S60 2nd and IDE is VC++ 6.0

  2. #2
    Regular Contributor
    Join Date
    May 2005

    Re: The error of read data from file

    About the first issue, I suppose the struct is padded up to 4 bytes, to avoid alignment problems.
    Mobile Sputnik: http://ptrmobile.blogspot.com/

Similar Threads

  1. Does not read from file
    By osho123 in forum Symbian
    Replies: 0
    Last Post: 2006-12-01, 12:52
  2. data file read and write
    By toinks in forum Symbian
    Replies: 28
    Last Post: 2006-11-07, 08:27
  3. Replies: 7
    Last Post: 2006-11-03, 01:52
  4. Replies: 0
    Last Post: 2006-06-05, 18:08
  5. socket read hangs until socket is closed
    By camroe in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2005-07-21, 09:44

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts