0

I've been checking this code but I don't see why my program isn't creating any jpg. Could you help me to guess why? The program is compiling without errors. Thank you

include

#include

typedef uint8_t byte;

typedef struct{ byte block[512]; } attribute((packed)) BUFFER;

int main(void) { // TODO BUFFER buffer; char title[8] = "";// Will hold the names of the jpegs files int i = 0;// Counter for the char array for jpegs int x = 0;// Condition for while loop

// open input file 
FILE* sdcard = fopen("card.raw", "r");

if (sdcard == NULL)
{
    printf("Could not open card.raw\n");
    return 2;
}

while(x == 0){
// read infile's BITMAPFILEHEADER
do{
    fread(&buffer, sizeof(BUFFER), 1, sdcard);
}while (!(buffer.block[0] == 0xff && buffer.block[1] == 0xd8 && buffer.block[2] != 0xff &&
(buffer.block[3] == 0xe0 || buffer.block[3] == 0xe1)));


sprintf(title, "03%d.jpg", i);
i++;

// open input file 
FILE* jpg = fopen(title, "w");

if (jpg == NULL)
{
    printf("Could not open jpg\n");
    return 1;
}


// write jpg
do{
fwrite(&buffer, sizeof(BUFFER), 1, jpg);
}while (!(buffer.block[0] == 0xff && buffer.block[1] == 0xd8 && buffer.block[2] != 0xff &&
(buffer.block[3] == 0xe0 || buffer.block[3] == 0xe1)));   

// close jpg
fclose(jpg);

if (i == 49)
    break;



}

fclose(sdcard);

return 0;

}

0

I saw the lines with buffer.block[2] != 0xff should have and == sign instead of !=. Solved

| improve this answer | |

You must log in to answer this question.

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