title: Search for Binary Pattern in C (Read buffered binary file)
body: <p>Hey there. I'm trying to write a small program that will read the four following bytes after the last occurrence of "0xFF 0xC0 0x00 0x11" which can be converted easily to binary or decimal. The purpose is that the 2-5 bytes following the last occurrence of that hex pattern represent the width and height of a JPEG file.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
   int main () {
    FILE * pFile;
    long lSize;
    char * buffer;
    size_t result;
  
    pFile = fopen ( "pano8sample.jpg" , "rb" );
    if(pFile==NULL){
     fputs ("File error",stderr);
     exit (1);
    }
  
    fseek (pFile , 0 , SEEK_END);
    lSize = ftell (pFile);
    rewind (pFile);
  
    printf("\n\nFile is %d bytes big\n\n", lSize);
  
    buffer = (char*) malloc (sizeof(char)*lSize);
    if(buffer == NULL){
     fputs("Memory error",stderr);
     exit (2);
    }
  
    result = fread (buffer,1,lSize,pFile);
    if(result != lSize){
     fputs("Reading error",stderr);
     exit (3);
    }
  
    //0xFF 0xC0 0x00 0x11 (0x08)
  
    //Logic to check for hex/binary/dec
  
    fclose (pFile);
    free (buffer);
    return 0;
   }
  </code></pre>
  
  <p>The problem is I don't know how to read from the buffered memory recursively and use the most recently read variable as an int to compare against my binary/hex/dec.</p>
  
  <p>How do I do this?</p>