Reading a .raw file while looking for .jpeg signatures
Binary mode
You should use binary mode to open your file instead of text mode.  So change:

FILE* inptr = fopen(infile, &quot;r&quot;);


to
FILE* inptr = fopen(infile, &quot;rb&quot;);

Otherwise, your CR/LF characters may get converted when you don't want them to be.
Buffer overrun
Your filename buffer is too short:

char filename[7];

char * name()
{
    if (filenum &lt; 10)
        sprintf(filename, &quot;00%d.jpg&quot;, filenum);
    else
        sprintf(filename, &quot;0%d.jpg&quot;, filenum);
    // ...


Here, your filenames will be something like &quot;000.jpg&quot; which require 7 characters plus a terminating null character, or 8 characters in total.  Also, if you generate 100 or more files, you will need even more characters.
Pad string with leading zeros
There is a better way to generate filenames padded with leading zeros.  Instead of:

if (filenum &lt; 10)
    sprintf(filename, &quot;00%d.jpg&quot;, filenum);
else
    sprintf(filename, &quot;0%d.jpg&quot;, filenum);


you can do this:
sprintf(filename, &quot;%03d.jpg&quot;, filenum);