0
int counter = 0;
FILE* inptr = fopen("card.raw", "r");
BYTE compare[512];
fread(&compare, 512, 1, inptr);
while (!feof(inptr)) {
    if ((compare[0] == 0xff) && (compare[1] == 0xd8) && (compare[2] == 0xff) && (compare[3] == 0xe0 || compare[3] == 0xe1)) {
        char filename[9];
        sprintf(filename, "%03d.jpg", counter);
        FILE* outptr = fopen(filename,"w");
        do {
            fwrite(&compare, 512, 1, outptr);
            fread(&compare, 512, 1, inptr);
        }
        while ((compare[0] != 0xff) || (compare[1] != 0xd8) || (compare[2] != 0xff) || (compare[3] != 0xe0 && compare[3] != 0xe1));      
        fclose(outptr);
        if (counter == 20) {
            return 1;
        } 
        counter++;
    }
    else {
        fread(&compare, 512, 1, inptr);
    }
}
fclose(inptr);
return 0;

For some reason, the program isn't ending. Any help appreciated.

0
0

Some comments:

  1. using feof in a while loop is tricky, consider another way of controlling the loop:

https://stackoverflow.com/questions/5431941/why-is-while-feof-file-always-wrong

  1. do you really need 9 characters for filename?
1
  • can anyone explain this line to me? sprintf(filename, "%03d.jpg", counter); unable to understand what is %03d.jpg.
    – Rohit Jain
    Jul 9 '19 at 7:37

You must log in to answer this question.

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