title: What does "ERROR interpreting JPEG image file( invalid JPEG file structure :SOS before SOF)" mean?
body: <p>I am trying to recover JPG's from a .raw file, when I try and open the ".jpg's" from the out put of my program, it gives that error, or it says some weird hexadecimal and says that it is an unsupported marker type for a JPEG (But it says it is a jpg!). What am I doing wrong?</p>
  
  <pre><code>     *
   * Recovers JPEGs from a forensic image.
   */
  
   //0xff 0xd8 0xff 0xe0
   //0xff 0xd8 0xff 0xe1
  
  #define BLOCK 512
  #define START1END 0xe0
  #define START2END 0xe1
  
  #include &lt;stdio.h&gt;
  #include &lt;cs50.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;stdint.h&gt;
  
  
  //sets the begins or jpgs
  uint8_t checkjpg1[4] = {0xff, 0xd8, 0xff, 0xe0};
  uint8_t checkjpg2[4] = {0xff, 0xd8, 0xff, 0xe1};
  
  //making variables
  int found = 0; 
  char title[BLOCK];
  FILE* img;
  int ifopen = 1;
  
  
  int main(int argc, char* argv[])
  {
      //opening file
      FILE* inptr = fopen("card.raw", "r");
      //checking if file opening failed
      if (inptr == NULL)
      {
          return 2;
      }
  
      //making buffer
      unsigned char buffer[BLOCK];
  
      //going through the file
      while(fread(&amp;buffer,sizeof(char),BLOCK,inptr) == BLOCK)
      {
           //checking if begin == the possible begin of jpg    
           if ((buffer[0] == checkjpg1[0] &amp;&amp; buffer[1] == checkjpg1[1] &amp;&amp; buffer[2] == checkjpg1[2]) &amp;&amp; 
           (buffer[3] == checkjpg1[3] || buffer[3] == checkjpg2[3]))
           {
              //if a jpg is not open
              if (ifopen == 1)
              {
                  //make one
                  found+=1;
                  sprintf(title,"00%d.jpg",found);
                  img = fopen(title,"a");
                  if(buffer[3] == checkjpg1[3])
                  {
                      fwrite(&amp;checkjpg1,sizeof(char),4,img);
                  }
  
              }
              else//else
              {
                  //end the one and open new one
                  fclose(img);
                  found +=1;
                  sprintf(title,"00%d.jpg",found);
                  img = fopen(title,"a");
                  if(buffer[3] == checkjpg1[3])
                  {
                      fwrite(&amp;checkjpg2,sizeof(char),4,img);
                  }
              }
           }
           else if (img != NULL)
           {
              fwrite(buffer,sizeof(char),BLOCK,img);
           }
       }
  
      fclose(inptr);
  }
  </code></pre>