I cannot validate whether the file is JPEG or not with a help of the pattern. Thanks in advance.
Here is my simple code:
typedef uint8_t BYTE;
int main(int argc, char* argv[])
{
char* cardName = "card.raw";
FILE* card = fopen(cardName, "r");
if(card == NULL)
{
printf("Could not open %s.\n", cardName);
return 2;
}
//read till the EOF
while(!feof(card)){
BYTE buffer[512];
int counter = 0;
int jpegNum = 0;
while(fread(&buffer, sizeof(BYTE), 1, card) == 1){
bool isJpeg = (buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff);
isJpeg = isJpeg && (buffer[3] == 0xe1 || buffer[3] == 0xe0);
while(isJpeg){
**I never get to here**
printf("here our %d JPEG",jpegNum);
counter++;
}
//after reading we are to close the card file
fclose(card);
}