The best I've been able to string this together, since Rhidian has spread questions and various fragments from replies around various threads and forums, is like this:Search through a file (likely a JPEG) opened in binary mode and search for this format's end-of-file indicator, which happens to be a hex value such as FFD9.
A quick hack, since I'm not exactly sure that this is what Rhidian is asking, might be something like this.
Code:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
static const char filename[] = "Ocean Wave.jpg";
FILE *file = fopen(filename, "rb");
if ( file != NULL )
{
unsigned char *buffer;
long i, size;
fseek(file, 0L, SEEK_END);
size = ftell(file);
rewind(file);
buffer = malloc(size);
if ( buffer != NULL )
{
static const unsigned char jpeg_eof[] = {0xFF,0xD9};
if ( fread(buffer, sizeof *buffer, size, file) == size )
{
for ( i = 0; i < size - 1; ++i )
{
if ( buffer[i] == jpeg_eof[0] && buffer[i + 1] == jpeg_eof[1] )
{
printf("i = %lX, size = %lX\n", i, size);
break;
}
}
}
}
free(buffer);
fclose(file);
}
else
{
perror(filename);
}
return 0;
}
/* my output
i = 121B7, size = 121B9
*/