You read the first 512 bytes (I used an array of uint8_t
instead of int
, but that should be possible as well), and print the first integer, representing the first 4 bytes.
If you throw card.raw
int the hex viewer, you'll see the first 512 bytes really are all-zeros:
~/workspace/freestyle/ $ xxd -l 512 -g 8 -c 32 card.raw
0000000: 0000000000000000 0000000000000000 0000000000000000 0000000000000000 ................................
0000020: 0000000000000000 0000000000000000 0000000000000000 0000000000000000 ................................
0000040: 0000000000000000 0000000000000000 0000000000000000 0000000000000000 ................................
0000060: 0000000000000000 0000000000000000 0000000000000000 0000000000000000 ................................
0000080: 0000000000000000 0000000000000000 0000000000000000 0000000000000000 ................................
00000a0: 0000000000000000 0000000000000000 0000000000000000 0000000000000000 ................................
00000c0: 0000000000000000 0000000000000000 0000000000000000 0000000000000000 ................................
00000e0: 0000000000000000 0000000000000000 0000000000000000 0000000000000000 ................................
0000100: 0000000000000000 0000000000000000 0000000000000000 0000000000000000 ................................
0000120: 0000000000000000 0000000000000000 0000000000000000 0000000000000000 ................................
0000140: 0000000000000000 0000000000000000 0000000000000000 0000000000000000 ................................
0000160: 0000000000000000 0000000000000000 0000000000000000 0000000000000000 ................................
0000180: 0000000000000000 0000000000000000 0000000000000000 0000000000000000 ................................
00001a0: 0000000000000000 0000000000000000 0000000000000000 0000000000000000 ................................
00001c0: 0000000000000000 0000000000000000 0000000000000000 0000000000000000 ................................
00001e0: 0000000000000000 0000000000000000 0000000000000000 0000000000000000 ................................
~/workspace/freestyle/ $
I would encourage you to look at a few more of those lines to understand what you can expect to read. The first non-zero byte is in the second sector (byte 512), the first JPEG image starts in the third (byte 1024).
So there's nothing wrong with your programme. Sure, you could read more sectors, and you could explicitly fclose
your input file at the end. But reading zero is not a problem with your code.