View Single Post

  #4 (permalink)  
Old 05-10-2008
Tim Roberts
 
Posts: n/a
Default Re: Why fread mistakes in reading binary file ?

Giacomo <giacomo.galilei@gmail.com> wrote:
>
><output>
>l1(2384) l2(2290) size(2290)
>Char(0) = d1(255) d2(255)
>Char(1) = d1(216) d2(216)
>Char(2) = d1(255) d2(255)
>Char(3) = d1(224) d2(224)
>Char(4) = d1(92) d2(0)
>Char(5) = d1(48) d2(16)
>Char(6) = d1(16) d2(74)
>Char(7) = d1(74) d2(70)
>...
></output>
>
>As you can see, the byte at position 4 is read as 0 (correctly, it is
>0) with fgetc and as a 2-byte-long sequence 92-48 by fread.. resulting
>in a corrupted file.


For the record, did you notice that 92 48 are the ASCII ordinals for "\0"?
Somebody was escaping the nulls in your string.
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
Reply With Quote