Getting zeros between data while reading a binary file in C

Posted by indiajoe on Stack Overflow See other posts from Stack Overflow or by indiajoe
Published on 2011-01-16T07:41:32Z Indexed on 2011/01/16 7:53 UTC
Read the original article Hit count: 278

Filed under:
|

I have a binary data which I am reading into an array of long integers using a C programme.

hexdump of the binary data shows, that after first few data points , it starts again at a location 20000 hexa adresses away. hexdump output is as shown below.

0000000 0000 0000 0000 0000 0000 0000 0000 0000

*

0020000 0000 0000 0053 0000 0064 0000 006b 0000

0020010 0066 0000 0068 0000 0066 0000 005d 0000

0020020 0087 0000 0059 0000 0062 0000 0066 0000

........ and so on... But when I read it into an array 'data' of long integers. by the typical fread command

fread(data,sizeof(*data),filelength/sizeof(*data),fd);

It is filling up with all zeros in my data array till it reaches the 20000 location. After that it reads in data correctly. Why is it reading regions where my file is not there? Or how will I make it read only my file, not anything inbetween which are not in file?

I know it looks like a trivial problem, but I cannot figure it out even after googling one night.. Can anyone suggest me where I am doing it wrong?

Other Info : I am working on a gnu/linux machine. (slax-atma distro to be specific)

My C compiler is gcc.

© Stack Overflow or respective owner

Related posts about c

    Related posts about binary