What data structure do I use to store the 512B blocks in a buffer?

Thinking about an array or ints? Or am I completely off?

  • Do you try to update appliance with update50 ? – Teodor Ilkov Nikolov Sep 6 '14 at 15:09
  • Ah sorry if I was't clear, I was working on recover from pset5! – Jesse Sep 6 '14 at 16:07

You definitely need to store it in an array. However, think about the size each element in that array should have. An int usually has 4 bytes. What you want is to look for jpg signatures, which are 4 bytes at the beginning of each 512 byte block potentially. In order to store these 4 individual bytes correctly, you need a buffer of a type like this:

BYTE buffer[512];

where BYTE should be defined as having exactly 8 bits, or one byte. Like this:

typedef uint8_t  BYTE; (from pset5, bmp.h)

To look for a jpg signature later, you can then easily access the first four bytes by looking at buffer[0], buffer[1], buffer[2], and buffer[3].

  • Would I have to include "bmp.h" header file since I'm accessing the typedef struct BYTE? – sisball8 Apr 9 '16 at 14:33
  • No, you can write the typedef directly into your recover.c code and create a type without needing to reference other documentation – Geist0504 Mar 20 '17 at 1:51
  • Actually, in order to call uint8_t, you need to #include <stdint.h> – Raoul Sep 15 '19 at 13:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .