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 

        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);


                **I never get to here** 
                printf("here our %d JPEG",jpegNum); 


    //after reading we are to close the card file


I don't think that's how booleans work.

It looks like you are trying to declare a function that evaluates to True if the .jpg file header is found. Try using an if statement instead.

if((buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff) && (buffer[3] == 0xe1 || buffer[3] == 0xe0))
  • Thank You lethaljd, I solved the problem by initializing isJpeg to false before reading into buffer. Dec 17 '14 at 5:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .