while( !feof(card))
{
FILE *f1=fopen(gp[i],"a"); //Opens a new file to store the bytes in
fread(buffer1, sizeof(BYTE), 512, card); //Reads a set of bytes from the card
if (buffer1[0] == 0xff && buffer1[1] == 0xd8 && buffer1[2] == 0xff && buffer1[3]/0x10==0x0e) //Checks whether the first 4 bytes match the start of a jpg
{
fwrite(buffer1, sizeof(BYTE), 512, f1); //Writes the bytes on to the opened file
fread(buffer1, sizeof(BYTE), 512, card); //Reads the next set of bytes from the card
while (buffer1[0] != 0xff && buffer1[1] != 0xd8 && buffer1[2] != 0xff && buffer1[3]/0x10!=0x0e) //Repeats the below process till we find the start of a new jpg
{
fwrite(buffer1, sizeof(BYTE), 512, f1); //Writes the bytes on to the opened file
fread(buffer1, sizeof(BYTE), 512, card); //Reads the next set of bytes from the card
}
fclose(f1);
i++;
}